svelte
svelte copied to clipboard
Extend props from HTML Element
we can update ElProps type to also extend HTML Attributes. https://github.com/sveltejs/language-tools/issues/442#issuecomment-1338090276
<script lang="ts">
interface $$Props extends svelte.JSX.HTMLAttributes<HTMLButtonElement> {
error: boolean; // error is explicitly typed as boolean to consumers of the component
}
export let error; // error is implicitly typed as any within the component
</script>
<button class:error {...$$restProps}>
<slot />
</button>
Heads up, you should use the new types coming with Svelte version v3.55.0 instead:
<script lang="ts">
import type { HTMLButtonAttributes } from 'svelte/elements';
interface $$Props extends HTMLButtonAttributes {
error: boolean; // error is explicitly typed as boolean to consumers of the component
}
export let error; // error is implicitly typed as any within the component
</script>
<button class:error {...$$restProps}>
<slot />
</button>
Heads up, you should use the new types coming with Svelte version v3.55.0 instead:
<script lang="ts">
import type { HTMLButtonAttributes } from 'svelte/elements';
interface $$Props extends HTMLButtonAttributes {
error: boolean; // error is explicitly typed as boolean to consumers of the component
}
export let error; // error is implicitly typed as any within the component
</script>
<button class:error {...$$restProps}>
<slot />
</button>