Svelte Adds Official TypeScript Support

The Svelte JavaScript framework leverages TypeScript, but until recently, it was challenging to use TypeScript to create Svelte web apps. The latest Svelte updates add official TypeScript support to Svelte.

As explained by TypeScript team member Orta Therox:

It's been by far the most requested feature for a while, and it's finally here: Svelte officially supports TypeScript. We think it'll give you a much nicer development experience — one that also scales beautifully to larger Svelte code bases — regardless of whether you use TypeScript or JavaScript.

Before this update, using TypeScript with Svelte required combining many different tools. TypeScript support in Svelte allows TypeScript within script blocks, type checking of Svelte components, auto-completion hunts when authoring components and their markup, and TypeScript understanding the Svelte component API.

To get started with TypeScript with Svelte, developers should install the Svelte template and Svelte TypeScript app and run a TypeScript setup script:

 npx degit sveltejs/template svelte-typescript-app  cd svelte-typescript-app  node scripts/setupTypeScript.js

There is also now a Svelte TypeScript VSCode extension available. It is also possible to add TypeScript support to existing Svelte projects. TypeScript support for the Sapper framework on top of Svelte is currently under development.