Open Black1358 opened 1 month ago
Please provide a reproduction (via sveltelab.dev or stackblitz or Github repo) so we can look into why the .svelte.ts
file wasn't analyzed.
https://github.com/Black1358/svelte-error-ts
I created a repository and found what is the trigger of my problem. For WebStorm, I changed the target in the compilerOptions (tsconfig). The ES2020 target is incompatible and throws an error in this case.
p.s. With ES2022 all works correctly
This is a documentation issue for TS usage. I outlined the requirements before over here.
You may have a TS configuration that specifies a
target
(or uses the default) which causes the class to be compiled down to a function for compatibility with < ES6 or the class field initializers may be turned into constructor assignments.Hence you have to make sure the target is at least
"es6"
or"es2015"
and if the target is lower than"es2022"
thenuseDefineForClassFields
has to be set totrue
(see documentation and notes on default value).
If constructor assignments are allowed (#11455), just the transpilation of classes would need to be prevented.
Describe the bug
This code throw Error when file named with .ts extention:
CompileError:
$state(...)
can only be used as a variable declaration initializer or a class fieldIf the file is named .js, everything is working correctly.
Reproduction
I've been researching the internal files and this is what I found:
svelte\src\compiler\phases\2-analyze:
Logs
System Info
Severity
annoyance