Skip to content

Instantly share code, notes, and snippets.

@chanced
Created October 4, 2021 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chanced/bfc4f4bfdd60077f30d0e0b043c5f81f to your computer and use it in GitHub Desktop.
Save chanced/bfc4f4bfdd60077f30d0e0b043c5f81f to your computer and use it in GitHub Desktop.
Couple of utility types for extracting svelte constructor options & svelte component props
export type SvelteComponentConstructorOptions<T> = T extends abstract new (
opts: Svelte2TsxComponentConstructorParameters<infer P>,
) => any
? Svelte2TsxComponentConstructorParameters<P>
: never;
export type SvelteComponentProps<T> = T extends abstract new (
opts: Svelte2TsxComponentConstructorParameters<infer P>,
) => any
? Svelte2TsxComponentConstructorParameters<P>["props"]
: never;
@chanced
Copy link
Author

chanced commented Oct 4, 2021

Usage:

import MyComponent from "./MyComponent.svelte"
type MyComponentProps = SvelteComponentProps<typeof MyComponent>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment