DEV Community

Cover image for Extending a HTML Element in a Svelte Component using TypeScript
Henrique Ramos
Henrique Ramos

Posted on • Edited on

2

Extending a HTML Element in a Svelte Component using TypeScript

When using Svelte with TypeScript, all properties of a component should be typed. Props are declared by exporting a let. However, when creating a superset of an HTML element, one wouldn't want to extensively declare all props. Here's a solution for this:

<script lang="ts">
  import type { HTMLInputAttributes } from 'svelte/elements';

  interface $$Props extends HTMLInputAttributes {
    prop: string;
  }

  export let prop: string;
  // ...
</script>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay