Hacker News new | ask | show | jobs
by tacone 644 days ago
You can use typescript on plain js files, just for type checking, without the need of a build.
2 comments

I guess you mean relying only on type inference? That will only get you so far. E.g. function parameters for freestanding functions would still be untyped. For those to be typed you need TypeScript or JSDoc annotations as OP noted.
Probably the OP meant “allowJs” and “noEmit” flags give you limited actual typechecking in your JS files
Exactly. You would use jsconfig in place of tsconfig, and disable the build just like you said. At that point you can use JSDoc for typing as well as .ts.d files when the JSDoc is not enough.

It's a bit more verbose, but overall I find it refreshing.

I'm already enabling @ts-check so they the jsdocs actually do something!