Releases: carbon-design-system/sveld
v0.22.0
v0.21.0
Breaking Changes
Fixes
- prefix internal
RestProps
type with$
to avoid conflicts withRest.svelte
as a component name (9534dd4, #148)
The strategy to generating types for exported props has changed. Previously, a TypeScript error would occur for a scenario in which ComponentProps
would incorrectly extend RestProps
.
Before
type $RestProps = SvelteHTMLElements["ul"] & SvelteHTMLElements["ol"];
// ❌ TypeScript expresses an error because `type` is a native attribute on `ul` and `ol` elements.
export interface ComponentProps extends $RestProps {
type: "ordered" | "unordered";
}
The solution is to do the following:
- Use a type alias instead of interface for exported component props.
- Omit keys in component props from
RestProps
. - Exported component props is the intersection of
RestProps
(omitting component prop keys) and component props.
After
type $RestProps = SvelteHTMLElements["ul"] & SvelteHTMLElements["ol"];
type $Props = {
type: "ordered" | "unordered";
}
// ✅ ComponentProps combines `RestProps` with `$Props`, omitting the custom `type` prop from `$RestProps`.
export type ComponentProps = Omit<$RestProps, keyof $Props> & $Props;
v0.20.3
v0.20.2
v0.20.1
v0.20.0
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>
> {}
v0.19.2
Fixes
ComponentParser
should remove carriage returns (Windows)
This package is now published with provenance.