svelte
svelte copied to clipboard
Identifier has alreay been declared error when naming a type the same as a variable in svelte5 script
Describe the bug
cant have smae name as variable ...
after using @sveltejs/[email protected]
src/routes/+page.svelte:4:12 Identifier 'data' has already been declared
src/routes/+page.svelte:4:12
2 | import Counter from '$lib/Counter.svelte';
3 | type data = {}
4 | export let data;
^
5 | </script>
Reproduction URL
<script lang="ts">
import Counter from '$lib/Counter.svelte';
type data = {}
export let data;
</script>
Hello {data.name}!
Reproduction
Logs
-
System Info
-
adding info from @gtm-nayan
cause is in acorn-typescript that just has one scope for both https://github.com/TyrealHu/acorn-typescript/blob/8956dc50370c7ee2ea97a3c903611079192b28d5/src/index.ts#L2720 https://github.com/acornjs/acorn/blob/12ad1164a70dbe804f1ece822f34d100545f1afa/acorn/src/lval.js#L267
In the meantime, either name them differently, or reenable the script preprocessor in your config (it was disabled by default for vite-plugin-svelte 4): preprocess: vitePreprocess({ script: true })
reenable the script preprocessor in your config (it was disabled by default for vite-plugin-svelte 4): preprocess: vitePreprocess({ script: true })
@dummdidumm I tried this and it works, but is there a way to get rid of the red squiggly lines