1
1
/* 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'
3
11
4
- type IS_MODERN_SVELTE = Svelte . Component extends ( ...args : any [ ] ) => any
12
+ type IS_MODERN_SVELTE = ModernComponent extends ( ...args : any [ ] ) => any
5
13
? true
6
14
: false
7
15
16
+ type IS_LEGACY_SVELTE_4 =
17
+ EventDispatcher < any > extends ( ...args : any [ ] ) => any ? true : false
18
+
8
19
/** A compiled, imported Svelte component. */
9
20
export 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 ,
12
23
> = 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 >
15
28
16
29
/**
17
30
* The type of an imported, compiled Svelte component.
18
31
*
19
32
* In Svelte 5, this distinction no longer matters.
20
33
* In Svelte 4, this is the Svelte component class constructor.
21
34
*/
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
25
38
26
39
/** 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 >
28
41
29
42
/**
30
43
* The exported fields of a component.
31
44
*
32
45
* In Svelte 5, this is the set of variables marked as `export`'d.
33
46
* In Svelte 4, this is simply the instance of the component class.
34
47
*/
35
- export type Exports < C > = C extends Svelte . SvelteComponent
48
+ export type Exports < C > = C extends LegacyComponent
36
49
? C
37
- : C extends Svelte . Component < any , infer E >
50
+ : C extends ModernComponent < any , infer E >
38
51
? E
39
52
: never
40
53
@@ -43,7 +56,6 @@ export type Exports<C> = C extends Svelte.SvelteComponent
43
56
*
44
57
* In Svelte 4, these are the options passed to the component constructor.
45
58
*/
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