Skip to content

v0.20.0

Latest
Compare
Choose a tag to compare
@metonym metonym released this 20 Apr 21:31
· 8 commits to main since this release

Features

  • support component generics via the custom @generics tag

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.

Signature:

/**
 * @generics {GenericParameter} GenericName
 */

Example

/**
 * @generics {Row extends DataTableRow = any} Row
 */

The generated TypeScript definition will resemble the following:

export default class Component<Row extends DataTableRow = any> extends SvelteComponentTyped<
  ComponentProps<Row>,
  Record<string, any>,
  Record<string, any>
> {}