Jay's blog

Fact Check: Is Svelte Ditching Typescript?


Claim:

Svelte is dropping Typescript in favor of JSDoc comments.

Rating:

<✅|❌> Mixed


A choice made by Svelte's creator, Rich Harris, rocked the web dev community today. If you're unfamiliar, Svelte is a front-end component framework that rides the fence between JavaScript framework and programming language. The seemingly contentious decision was to alter how the internal compiler uses Typescript.

The pull request, which was locked as "too heated" earlier today after it trended on Hacker News, at first glance may look like Typescript is being ditched for plain, old JavaScript. However, looks can be deceiving.

As explained in a video and a tweet by Harris, Typescript is not being ditched. Instead, the Svelte compiler code is moving towards an interesting and often overlooked feature of Typescript: JSDoc Typescript.

I've been using Typescript as my primary front-end language for about five years now, and I must admit I didn't know JSDoc TS was a thing until today. And I think Harris may be on to something here.

JSDoc TS uses special doc comment annotations that the Typescript compiler understands to add most of the benefits of Typescript's type checking to bog standard JavaScript code. The major advantage, which is the primary reason behind Harris's choice, is that you get the rich type-checking guarantees of Typescript without the required build step to strip out the Typescript and turn your code back into JavaScript.

I remember a time when there were no build steps required to develop a rich, interactive website. Then we started breaking out our files into modules, which is generally a good thing. But this requires a build step to at least concatenate all of your source files together before your code can run in the browser. More build steps were added until we ended up with a build pipeline.

Lamenting the loss of the simplicity of web development is so common that it's become a meme in developer circles. But the good news is that with overwhelming support of modules and import maps in browsers, I think we're closer than ever to returning to a build-less front-end world. But I don't want to give up the advantages of Typescript.

Maybe JSDoc TS is the best of both worlds? I'm willing to give it a shot next time I start a small personal project.