Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Extend props from HTML Element #671

Open
TheHadiAhmadi opened this issue Dec 17, 2022 · 1 comment
Open

Extend props from HTML Element #671

TheHadiAhmadi opened this issue Dec 17, 2022 · 1 comment
Labels

Comments

@TheHadiAhmadi
Copy link
Collaborator

we can update ElProps type to also extend HTML Attributes.
sveltejs/language-tools#442 (comment)

<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>
@dummdidumm
Copy link

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>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants