fix: ensure typings for <svelte:options> are picked up (Svelte 4) by dummdidumm · Pull Request #12902 · sveltejs/svelte (original) (raw)
I brought this change in my project ... but I am getting this typescript error
Do you mean "I didn't get this error before, but now I do"?
As for how to fix it: That's tricky because there's not really a way to use typescript in the template in Svelte 4. In Svelte 5 you could do this:
extend: (customElementConstructor) => {
return class extends customElementConstructor {
host: HTMLElement;
constructor() {
super();
this.host = this; // or this.shadowRoot, or whatever you need
}
};
}}}
In Svelte 4 you could move your function that defines the extension into a separate file to type it properly there
<svelte:options customElement={{ tag: 'custom-element', extend: extendClass }} />