Currently, to define generics for a Svelte component, you must use generics attribute on the script tag. Note that this feature is experimental and may change in the future.
However, the generics attribute only works if using lang="ts"; the language server will produce an error if generics is used without specifying lang="ts".
<!-- This causes an error because `lang="ts"` must be used. -->
<script generics="Row extends DataTableRow = any"></script>
Because sveld is designed to support JavaScript-only usage as a baseline, the API design to specify generics uses a custom JSDoc tag @generics.
Currently, to define generics for a Svelte component, you must use
generics
attribute on the script tag. Note that this feature is experimental and may change in the future.However, the
generics
attribute only works if usinglang="ts"
; the language server will produce an error ifgenerics
is used without specifyinglang="ts"
.Because
sveld
is designed to support JavaScript-only usage as a baseline, the API design to specify generics uses a custom JSDoc tag@generics
.Signature:
Example
The generated TypeScript definition will resemble the following: