-
-
Notifications
You must be signed in to change notification settings - Fork 114
TS enums no longer get transpiled as expected starting with [email protected]
in *.svelte
files
#961
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
Comments
svelte5 understands ts syntax in .svelte files without needing a preprocessor, however it does not work with typescript features that have code output. for that to work you have to change |
Ah okay, I'm curious why that's the default? 🤔 But thanks for the quick response! |
we might reevaluate that default. in general i think most users/components don't need this feature so it would save processing time. But it is kind of opaque and the current feedback isn't great as you already experienced. Would you be less concerned about this default if a message told you about it? |
Yeah maybe svelte-check could warn if |
@dominikg this should be handled with an error at compile time or it will errors on runtime only as in my case. Plus, I think the default should be changed to handle this by default if I use Typescript. |
Can you please re-open this, @ndom91? |
Sure, happy to discuss |
forcing an extra unneeded transpile on all users just because some users use enums or other code generating features of typescript in some files is not great. Ideally we find a way to avoid this scenario. For the record the breaking changes of 4.0 do mention that scripts are no longer preprocessed for typescript by default
So this might also just be something that needs better communication / warnings. There's also the question of how useful enums in .svelte script blocks are. Another way of avoiding this problem is putting them in .ts files and import. |
This is not an issue with enums only, with the below code: <script lang="ts">
// ...
$effect(() => {
// ...
if (input) {
input.value = someOne || someTwo;
}
});
</script> I get:
with Or this other code: <script lang="ts">
const options: Partial<BaseOptions> = {
// ...
onReady() {
//...
} // <-- here the red error
};
</script> the error:
So now I think we should decide if Svelte 5 can handle typescript or not alone or am I wrong? |
Just upgraded to 4 and ran into this issue. Took a while to debug with the error messages only being something like expected "{" but got ";", I think the issue was I didn't even know it was enum related until digging deep into the codebase. enabled script: true and it works fine. |
vite-plugin-svelte@4 is going to continue to keep script: false as the default. Documentation will be updated to reflect this. svelte itself is going to get better messages to let users know that these features require a preprocessor, which v-p-s can then pick up to suggest enabling script. see sveltejs/svelte@194570d In general i would recommend not to put ts code that uses these in .svelte files, instead put them into .ts files and import it into .svelte files. |
docs update #974 |
The current message says
Is there any reason why they are discouraged? I'm not aware that the Typescript team is discouraging them at all. |
please use our discord |
Describe the bug
We have a component which uses an
enum
as a value in a.svelte
file. When using@sveltejs/[email protected]
the following works as expected. However, when upgrading to@sveltejs/[email protected]
, we begin seeing errors aboutReferenceError: Can't find variable: Action
In
3.1.1
the code above produced compiled output like this:Whereas in
4.0.0-next.0
that output is missing entirely. This seems to only be effecting enums in .svelte files. Enums used like this in .ts files are unaffected.Reproduction URL
https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAA1WQwWrDMAyGX8WIQVoWuu2aNoWy3Rd6rXtwPWV4c-Rgy4UR8u7Ddrt2B2NL-iV9_ifojcUAzWECUgNCA7txhBr4Z0xBOKNlhBqCi16nzCZob0YWVtFnK4GDhK0kyUhxEDvNxpGYUkLyq0fFKFpR6fzqfFXfV9686vlWzmHnqySZJaVLOwosVJ4aRCveT1-oeXVWNmJYlG3L9U1p1QltEl4IDkWyKvuOjaguTN3-ivJfkhnudAWx2xeovCkdiyy0i5ToHwIrxsVz5iDJfaTigiHtcUDixfLKU3oeW_Gyvvxy81T8TB7S5hSZHQlH2hr93U5_I-bscc6GRkx5Tu4uHVuoYXAfpjf4AQ37iPNx_gWxO40x3AEAAA==
Reproduction
In the above svelte-5 playground URL, you can see that the
enum Action
also results in the error "Action is not defined".This link leads to a PR of our project where I bumped the dependencies and moved the
enum Action
down from the<script lang="ts" context="module">
to the normal<script />
tag because the enum was no longer being imported from anywhere and it's simpler that way. The PR also includes bumping a few Svelte related packages, except thevite-plugin-svelte
, because that was giving us troubles.Logs
No response
System Info
The text was updated successfully, but these errors were encountered: