Skip to content

Commit f4b1508

Browse files
authored
fix(svelte5): ensure typings are actually included in the module (#402)
1 parent f215ad8 commit f4b1508

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"types": "svelte-check",
7373
"types:legacy": "svelte-check --tsconfig tsconfig.legacy.json",
7474
"validate": "npm-run-all test:vitest:* test:jest types build",
75-
"build": "tsc -p tsconfig.build.json",
75+
"build": "tsc -p tsconfig.build.json && cp src/component-types.d.ts types",
7676
"contributors:add": "all-contributors add",
7777
"contributors:generate": "all-contributors generate",
7878
"preview-release": "./scripts/preview-release"

src/component-types.d.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import type * as Svelte from 'svelte'
23

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

66
/** A compiled, imported Svelte component. */
7-
export type Component<P> = IS_MODERN_SVELTE extends true
8-
? Svelte.Component<P> | Svelte.SvelteComponent<P>
7+
export type Component<
8+
P extends Record<string, any>,
9+
E extends Record<string, any>,
10+
> = IS_MODERN_SVELTE extends true
11+
? Svelte.Component<P, E> | Svelte.SvelteComponent<P>
912
: Svelte.SvelteComponent<P>
1013

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

2124
/** The props of a component. */
22-
export type Props<C> = Svelte.ComponentProps<C>
25+
export type Props<C extends Component<any, any>> = Svelte.ComponentProps<C>
2326

2427
/**
2528
* The exported fields of a component.
@@ -29,7 +32,7 @@ export type Props<C> = Svelte.ComponentProps<C>
2932
*/
3033
export type Exports<C> = C extends Svelte.SvelteComponent
3134
? C
32-
: C extends Svelte.Component<unknown, infer E>
35+
: C extends Svelte.Component<any, infer E>
3336
? E
3437
: never
3538

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

0 commit comments

Comments
 (0)