on-internet
← Community

How to add types to spread component props

Stack Overflow ·

Is it possible to ensure type safety with components that are composed of others? For example, if I want to build a special kind of input with certain validation, etc that should extend my base input. BaseInput.svelte <script lang="ts"> export let value = ''; // + a lot more props </script> <input bind:value ... /> AgeInput.svelte - this extends BaseInput <script lang="ts"> import BaseInput from './BaseInput.svelte' export let {...inputProps}: /* Can we spread and infer BaseInput props? */; </script> <BaseInput {...inputProps} type="number" /> Can we infer the BaseInput props?

Comments

Sign in or sign up to comment and upvote.

No comments yet.