-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Svelte 5: differentiate between supported and unsupported TypeScript features #11502
Comments
Also: ts auto accessor modifier (REPL) |
These features are robust and widely used across the industry. Decorators are especially useful.
Why is it ok for Svelte to add features when compiling to javascript, but not Typescript? |
related: sveltejs/svelte#11502
* overview * getting started * component fundamentals * basic markup * control flow * snippets * styles and classes * transitions and animations (WIP, needs motion and tweened, reference should have more details so we can point to it) * actions WIP (add $effect) * bindings * special elements * data fetching (WIP, what else can we put there?) * stores * imperative component api * reactivity fundamentals * contex * lifecycle hooks * state * debugging * fix * more details on $state.is, closes sveltejs/svelte#12167 * side effects * typescript related: sveltejs/svelte#11502 * custom elements * events
I stumbled upon this issue after realizing my use of |
same issue here in regards of |
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. |
Hi all, I found this issue while trying to figure out why my enums were causing issues after I updated to Svelte 5 - personally, I do think it's a little confusing to basically have 2 "levels" of typescript support (one where runtime features won't work, and another with I think that Svelte should allow all Typescript features by default, regardless of viewpoint on runtime features. Googling for Typescript issues may give solutions that use these runtime features, only for a newbie to implement them in Svelte and be met with errors. Now, I realize that the goal is to make these errors easy to understand and fix (or workaround), but I still respectfully disagree with the overall direction. If someone doesn't want to use runtime features, they can just choose not to use them, or maybe the default could be Thanks to all who have worked on Svelte[Kit] - it's an amazing framework that has served me well for years, and certainly many more. |
@McGaelen my sentiment, exactly. Svelte should remain an unopinionated framework. |
It's not a question of opinions. There are two TypeScripts — there's JavaScript+types, which Bloomberg refer to (correctly IMHO) as Modern TypeScript, and there's the stuff that affects behaviour at runtime. For historical reasons they're both 'TypeScript' but they're entirely different beasts. |
While we can discuss the merits of different TypeScript runtime features (and likely agree on how bad they are), I agree that people should be free to use or avoid language features based on their needs rather than limitations of their frontend framework. If Svelte wants to recommend against certain TypeScript features, that's fine - but semantically appropriating the word "TypeScript" itself to mean "a subset of Typescript that excludes those features" doesn't seem like the best way to do it, especially when thousands of companies / developers already use of them. If we can only support a subset of TypeScript, our documentation should say that (and ideally explain why such a limitation exists), regardless of what TypeScript features we think people "should" use. |
I had the issue with Fix: add this in preprocess: vitePreprocess( |
Just in case somebody somebody misses it, there is a typo, here the correct one: |
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:
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
The text was updated successfully, but these errors were encountered: