I have the Svelte Beta extension installed and have restarted the language server. My svelte.config.js
is:
const sveltePreprocess = require('svelte-preprocess');
module.exports = {
preprocess: sveltePreprocess(),
};
However, the extension does not seem to help VS Code understand that my code is Typescript, since it gives an error on type annotation:
Type annotations can only be used in TypeScript files. javascript
Also interesting, if I change lang="typescript"
to type="text/typescript"
, the syntax colours completely go away, as well as the error:
System (please complete the following information):
Can you post the entire file's code here or an example repo? I can't reproduce it. Don't need to include all the script but needs other top-level tags
Here's a minimal reproduction:
<script lang="typescript">
let countExcludingUser: number = 0;
</script>
<p>Hi</p>
I disabled all extensions except Svelte Beta and restarted VS Code, with no success.
I only managed to reproduce once and no luck after that. Can you try it again it the latest build 99.0.22? There is some update about preprocessing in this version. If it still persists can you make an example repo?
From your description it seems that SveltePlugin.ts
does get that it should preprocess with Typescript because there is no Svelte syntax error like "unexpected token". On the other hand TypescriptPlugin.ts
does - for some reason - not recognize that you use Typescript but thinks it's Javascript instead. Really strange.. An example repo would certainly help.
Ah, so the problem was because I had this in my VS Code "User" settings:
"files.associations": {
"*.svelte": "html"
},
Now that I've removed it, everything seems to work fine.
Most helpful comment
Ah, so the problem was because I had this in my VS Code "User" settings:
Now that I've removed it, everything seems to work fine.