11/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-redundant-type-constituents */
2- import type * as Svelte from 'svelte'
2+ import type {
3+ Component as ModernComponent ,
4+ ComponentConstructorOptions as LegacyConstructorOptions ,
5+ ComponentProps ,
6+ EventDispatcher ,
7+ mount ,
8+ SvelteComponent as LegacyComponent ,
9+ SvelteComponentTyped as Svelte3LegacyComponent ,
10+ } from 'svelte'
311
4- type IS_MODERN_SVELTE = Svelte . Component extends ( ...args : any [ ] ) => any
12+ type IS_MODERN_SVELTE = ModernComponent extends ( ...args : any [ ] ) => any
513 ? true
614 : false
715
16+ type IS_LEGACY_SVELTE_4 =
17+ EventDispatcher < any > extends ( ...args : any [ ] ) => any ? true : false
18+
819/** A compiled, imported Svelte component. */
920export type Component <
10- P extends Record < string , any > ,
11- E extends Record < string , any > ,
21+ P extends Record < string , any > = any ,
22+ E extends Record < string , any > = any ,
1223> = IS_MODERN_SVELTE extends true
13- ? Svelte . Component < P , E > | Svelte . SvelteComponent < P >
14- : Svelte . SvelteComponent < P >
24+ ? ModernComponent < P , E > | LegacyComponent < P >
25+ : IS_LEGACY_SVELTE_4 extends true
26+ ? LegacyComponent < P >
27+ : Svelte3LegacyComponent < P >
1528
1629/**
1730 * The type of an imported, compiled Svelte component.
1831 *
1932 * In Svelte 5, this distinction no longer matters.
2033 * In Svelte 4, this is the Svelte component class constructor.
2134 */
22- export type ComponentType < C > = IS_MODERN_SVELTE extends true
23- ? C
24- : new ( ... args : any [ ] ) => C
35+ export type ComponentType < C > = C extends LegacyComponent
36+ ? new ( ... args : any [ ] ) => C
37+ : C
2538
2639/** The props of a component. */
27- export type Props < C extends Component < any , any > > = Svelte . ComponentProps < C >
40+ export type Props < C extends Component > = ComponentProps < C >
2841
2942/**
3043 * The exported fields of a component.
3144 *
3245 * In Svelte 5, this is the set of variables marked as `export`'d.
3346 * In Svelte 4, this is simply the instance of the component class.
3447 */
35- export type Exports < C > = C extends Svelte . SvelteComponent
48+ export type Exports < C > = C extends LegacyComponent
3649 ? C
37- : C extends Svelte . Component < any , infer E >
50+ : C extends ModernComponent < any , infer E >
3851 ? E
3952 : never
4053
@@ -43,7 +56,6 @@ export type Exports<C> = C extends Svelte.SvelteComponent
4356 *
4457 * In Svelte 4, these are the options passed to the component constructor.
4558 */
46- export type MountOptions < C extends Component < any , any > > =
47- IS_MODERN_SVELTE extends true
48- ? Parameters < typeof Svelte . mount < Props < C > , Exports < C > > > [ 1 ]
49- : Svelte . ComponentConstructorOptions < Props < C > >
59+ export type MountOptions < C extends Component > = C extends LegacyComponent
60+ ? LegacyConstructorOptions < Props < C > >
61+ : Parameters < typeof mount < Props < C > , Exports < C > > > [ 1 ]
0 commit comments