Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TS top level errors in script explicit #753

Closed
pushkine opened this issue Jan 11, 2021 · 4 comments
Closed

Make TS top level errors in script explicit #753

pushkine opened this issue Jan 11, 2021 · 4 comments
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release.

Comments

@pushkine
Copy link
Contributor

<script lang="ts">
	declare const foo: string;
</script>

I was confused why this threw an error, Modifiers cannot appear here. ts(1184)
I didn't know but it makes sense that declare can only be used in the top-level

It's not self-evident for svelte users that script blocks don't accept such typescript top-level statements
maybe could the extension hint that the statement should be moved to a script context module block

Even better, a "quick fix" to move it into a script module ?

@pushkine pushkine added the bug Something isn't working label Jan 11, 2021
@dummdidumm
Copy link
Member

The instance script is converted to something that is inside a function called render. Another solution could be to move declare statements outside of that function through magicstring's move. It needs to be checked if other intellisense features like hover info/rename still work afterwards.

@pushkine
Copy link
Contributor Author

Moving it out would expose it in the scope of the script module, which is unexpected

@dummdidumm dummdidumm added feature request New feature or request and removed bug Something isn't working labels Jan 11, 2021
@dummdidumm
Copy link
Member

True, so we need to make the error message a little clearer. That can be added here, I imagine something like if (code === 1184) { message += "If you are using a declare statement, move it into the module script block" (Not sure what other statements need to be moved). Adding a quick fix could be done later if that happens too often, for now I'd hold off of that because of the complexity, also where to move it, people are likely to move it somewhere specific which we don't know in advance. A better alternative might be to only add a "create module script" quick fix which would only appear if that module script block does not exist yet.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Jan 12, 2021
dummdidumm added a commit that referenced this issue Jan 13, 2021
#753, #718

- make it more clear that the JSX-related message is the underlying error to diminish confusion
- add suggestion to ts error
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jan 13, 2021
@dummdidumm
Copy link
Member

Enhanced message. Omitted the create module script quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

2 participants