svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Svelte 5: differentiate between supported and unsupported TypeScript features

Open Rich-Harris opened this issue 9 months ago • 10 comments

Describe the problem

Svelte 5 supports TypeScript syntax natively, but it doesn't support TypeScript runtime features such as enums, using, decorators (related: #11397) and so on.

In general, a good piece of advice is 'don't use these features, they are a bad idea'. TypeScript isn't Babel — in 2024 it should be used for adding types, nothing more. But since not everyone is aware of this distinction or inclined to follow this advice, we need some way of handling these cases.

Describe the proposed solution

The compiler should error when encountering these features with a message that invites people to use the TypeScript preprocessor:

TypeScript decorators are a runtime feature that requires your code to be preprocessed before Svelte compiles it. See https://svelte.dev/docs/... for information on how to set up the preprocessor.

Not 100% sure what this would mean for TypeScript inside markup (or TypeScript that uses these features in .svelte.ts files, for that matter).

Importance

nice to have

Rich-Harris avatar May 07 '24 16:05 Rich-Harris

Also: ts auto accessor modifier (REPL)

fcrozatier avatar Jun 03 '24 09:06 fcrozatier

don't use these features, they are a bad idea

These features are robust and widely used across the industry. Decorators are especially useful.

TypeScript isn't Babel

Why is it ok for Svelte to add features when compiling to javascript, but not Typescript?

braebo avatar Jun 10 '24 18:06 braebo

I stumbled upon this issue after realizing my use of enum did not agree with the elimination of the Vite pre-processor. I too agree that it would be nice if all of TypeScript were supported. Having said that, if it cannot be had without the pre-processor, is not the end of the world, so long we can use said pre-processor. Thanks!

webJose avatar Jun 29 '24 05:06 webJose

same issue here in regards of enum in particular. It would be great if that could be support as it is quiet a useful feature (e.g. having a prop that is an enum that I want to define in my component rather then moving to a ts file).

fkrauthan avatar Sep 01 '24 03:09 fkrauthan

Errors for unsupported TypeScript features are thrown now. In the future we can look into supporting specific features. Enums for example are rather easy to transform, so we could do that.

dummdidumm avatar Sep 03 '24 11:09 dummdidumm