BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Svelte Adds Official TypeScript Support

Svelte Adds Official TypeScript Support

This item in japanese

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.

Bringing TypeScript support to Svelte was a substantial community effort among many different developers to bring their separate extensions together to form Svelte's official TypeScript support. Changes were needed to support TypeScript transpilation and TypeScript Language Services support for improvements to the IDE experience.

Svelte and its TypeScript support are open source software available under the MIT license. Contributions are welcome under the Svelte contribution guidelines.

Rate this Article

Adoption
Style

BT