-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
If component is generic, events and slot bindings are treated as any
in ESLint
#564
Comments
I did some research and it turns out that slot bindings are also only typed in VSCode but for ESLint they are simply So if I have this component: <script lang="ts">
let foo = { prop: true }
</script>
<slot {foo}></slot> <Component>
<div let:foo={bar}>{bar.prop}</div>
<Component> ESLint will let me know that |
Did more digging: However this doesn't seem to work for slot bindings -- those are still broken according to my testing. |
Even more digging: defining // script part
....
import Comp from './component.svelte';
.... code: // code part
....
(x);({ id: '1', value: 'something' })as ('Y' extends infer PROP?(PROP extends keyof import('svelte').ComponentProps<Comp>?(import('svelte').ComponentProps<Comp>[PROP]):(never)):(never));
(item: (Comp['$$slot_def']["SLOTNAME"]["PROPNAME"]))=>{if(item){(item.id);}};(Comp);` So it seems that the type for the slot prop is correctly referred to as I removed the generic from my component and tried again: now eslint is not complaining anymore about an unsafe member access. So instead of tl;dr: when a component is generic, slot bindings are not correctly typed. |
any
in ESLint
I was having a similar problem, though I unfortunately I am also seeing Did you face the same issue? And if so did you find a solution? I'd love an example of how you got your project set up if so. |
This is fixed in Svelte5. |
Before You File a Bug Report Please Confirm You Have Done The Following...
*.svelte
file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)What version of ESLint are you using?
9.10.0
What version of
eslint-plugin-svelte
andsvelte-eslint-parser
are you using?What did you do?
Configuration
Consider this code:
As you can see
X
should be typed as an object, which is correctly detected by VSCode:However when running eslint with type-checking rules enabled, eslint produces an error indicating, that
X
is simplyany
:Further investigation with more rules that check for types (i.e. @typescript-eslint/no-unsafe-assignment and @typescript-eslint/no-unsafe-member-access) confirm that for eslint,
X
is simplyany
What did you expect to happen?
I wanted eslint to not throw the error since
X
is properly typed.What actually happened?
eslint throws an error indicating that
X
is simply any.Link to GitHub Repo with Minimal Reproducible Example
https://github.com/ptrxyz/bug-svelte-eslint-componentevents/tree/main
Additional comments
No response
The text was updated successfully, but these errors were encountered: