Skip to content

fix(svelte5): ensure typings are actually included in the module #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"types": "svelte-check",
"types:legacy": "svelte-check --tsconfig tsconfig.legacy.json",
"validate": "npm-run-all test:vitest:* test:jest types build",
"build": "tsc -p tsconfig.build.json",
"build": "tsc -p tsconfig.build.json && cp src/component-types.d.ts types",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate",
"preview-release": "./scripts/preview-release"
Expand Down
20 changes: 12 additions & 8 deletions src/component-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type * as Svelte from 'svelte'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type IS_MODERN_SVELTE = any extends Svelte.Component ? false : true

/** A compiled, imported Svelte component. */
export type Component<P> = IS_MODERN_SVELTE extends true
? Svelte.Component<P> | Svelte.SvelteComponent<P>
export type Component<
P extends Record<string, any>,
E extends Record<string, any>,
> = IS_MODERN_SVELTE extends true
? Svelte.Component<P, E> | Svelte.SvelteComponent<P>
: Svelte.SvelteComponent<P>

/**
Expand All @@ -19,7 +22,7 @@ export type ComponentType<C> = C extends Svelte.SvelteComponent
: C

/** The props of a component. */
export type Props<C> = Svelte.ComponentProps<C>
export type Props<C extends Component<any, any>> = Svelte.ComponentProps<C>

/**
* The exported fields of a component.
Expand All @@ -29,7 +32,7 @@ export type Props<C> = Svelte.ComponentProps<C>
*/
export type Exports<C> = C extends Svelte.SvelteComponent
? C
: C extends Svelte.Component<unknown, infer E>
: C extends Svelte.Component<any, infer E>
? E
: never

Expand All @@ -38,6 +41,7 @@ export type Exports<C> = C extends Svelte.SvelteComponent
*
* In Svelte 4, these are the options passed to the component constructor.
*/
export type MountOptions<C> = IS_MODERN_SVELTE extends true
? Parameters<typeof Svelte.mount<Props<C>, Exports<C>>>[1]
: Svelte.ComponentConstructorOptions<Props<C>>
export type MountOptions<C extends Component<any, any>> =
IS_MODERN_SVELTE extends true
? Parameters<typeof Svelte.mount<Props<C>, Exports<C>>>[1]
: Svelte.ComponentConstructorOptions<Props<C>>