-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
type svelte:self
#1229
Comments
From a typing perspective that's really tricky because we use the component within its own definition, might very well be that typescript bails out here and we need to find some workaround. |
i just spent like an hour debugging only to find out i was passing invalid arguments to
typescript is usually pretty good with handling recursive types, and only really complains in cases where it believes the recursion to be infinite. i have no idea how svelte component types work under the hood though, but assuming it's something like this, there shouldn't be an issue: declare class SomeComponent {
constructor(value: number)
self: typeof SomeComponent // no error
}
new (new SomeComponent(1)).self(1) // no error |
On the smae note, I'd be very interested if there were a way to access a component's own types, like |
Is this maybe somehow going to be easier to implement with Svelte 5? |
I'm working with a lot of tree structures where svelte:self is heavily used and I regularly run into type issues because |
<!-- tree.svelte -->
<script lang="ts">
import Tree from './tree.svelte'; // it's me, the current file!
type TreeItem = {
name: string;
children?: TreeItem[];
};
export let node: TreeItem;
</script>
<div>{node.name}</div>
<div>
{#each node.children ?? [] as child}
<Tree /> <!-- Property 'node' is missing in type '{}' but required in type '{ node: TreeItem; }'. ts(2741) -->
{/each}
</div> |
Oh nice, I didn't know that. Then I would think it's best to remove |
Describe the problem
When you use
svelte:self
in a typescript component, it seems to not have any type checksDescribe the proposed solution
I would like
svelte:self
to be typed according to the props in the current componentAlternatives considered
You could always just not use types on
svelte:self
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: