svelte
svelte copied to clipboard
Svelte 5: differentiate between supported and unsupported TypeScript features
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
Also: ts auto accessor modifier (REPL)
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?
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!
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).
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.