You don't (always) need TypeScript
When I heard about SvelteKit moving away from TypeScript and converting stuff to JSDoc I got interested in exploring a little bit the API and see what it can do.
Turns out it is really simple: The setup as expected is super easy and the API is surprisingly clean. You are still going to use your TypeScript Language Server for the type checking, but you only need a // @ts-check
on the file you want to type check, or even better, create a jsconfig.json
file with
and you are good to go. No libraries to install and no files to transpile.
I ended up creating a small project to try out JSDoc and other ideas (maybe future posts about them). You can browse the project and see that you can easy define reusable types with @typedef
, define inline types for your variables with @type
, type function parameters with @params
and so on, the API is rich and the names easy to remember. The only thing that I found out that is kinda kinda annoying is the tag @template
used to make generic types, it just makes any generic type occupy multiple lines which is visual pollution in the code editor.
To start using JSDoc
I recommend the docs in the TypeScript website, link here. As always you can learn a lot by reading good code, have a look at SvelteKit github repo.