Skip to content

v0.21.0

Compare
Choose a tag to compare
@metonym metonym released this 27 Oct 22:28
· 10 commits to main since this release

Breaking Changes

  • use type alias instead of interface for exported component props type (d9cf04a, #138)

Fixes

  • prefix internal RestProps type with $ to avoid conflicts with Rest.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;