microsoft / vscode-html-languageservice

Language services for HTML
MIT License
229 stars 110 forks source link

Allow writing TypeScript in Script tags with @ts-check #156

Open ivanjeremic opened 1 year ago

ivanjeremic commented 1 year ago

Be able to write TypeScript in Script Tags inside .html files. (I'm not asking for compilation support for .html files only allow the usage and check of TS inside .html files Script Tag)

When we do this: we get the error Type annotations can only be used in TypeScript files. when hovering over the Type.

<script>
  let foo: number = 0;
  foo = "hello";
</script>

//@ts-check works and gives me checks and squiggly lines but still gets not rid of the error above. A Solution would be if this would work.

<script>
 //@ts-check 
  import { mod } from "./this/should/give/autocomplete"
  let foo: number = 0;
  foo = "hello";

  mod();
</script>

The ideal would be if //@ts-check allows the use of TypeScript inside Script Tags.

Heath123 commented 1 year ago

I’d like this too, with a way to specify a tsconfig.json

Heath123 commented 1 year ago

If you go to this function https://github.com/microsoft/vscode/blob/ce00cd7812aa1c8fa63cf5630f28fd3f9197fdc6/extensions/html-language-features/server/src/modes/javascriptMode.ts#L29-L34 and add return ts.ScriptKind.TS; at the start of the function then it works but it also causes errors because it checks things you might not want checked as well

qrhfz commented 1 year ago

usually //@ts-check is used with jsdoc for type annotation instead of typescript syntax