Skip to content

Commit e72c8c4

Browse files
authored
Fix default export return type (#686)
Adjust Svelte2TsxComponent class function creator for better type inference.
1 parent 1521818 commit e72c8c4

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

packages/svelte2tsx/svelte-shims.d.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,7 @@ declare class Svelte2TsxComponent<
2424
*/
2525
$$slot_def: Slots;
2626
// https://svelte.dev/docs#Client-side_component_API
27-
constructor(options: {
28-
/**
29-
* An HTMLElement to render to. This option is required.
30-
*/
31-
target: Element;
32-
/**
33-
* A child of `target` to render the component immediately before.
34-
*/
35-
anchor?: Element;
36-
/**
37-
* An object of properties to supply to the component.
38-
*/
39-
props?: Props;
40-
hydrate?: boolean;
41-
intro?: boolean;
42-
$$inline?: boolean;
43-
});
27+
constructor(options: Svelte2TsxComponentConstructorParameters<Props>);
4428
/**
4529
* Causes the callback function to be called whenever the component dispatches an event.
4630
* A function is returned that will remove the event listener when called.
@@ -62,7 +46,26 @@ declare class Svelte2TsxComponent<
6246
$inject_state(): void;
6347
}
6448

65-
type AConstructorTypeOf<T> = new (...args: any[]) => T;
49+
interface Svelte2TsxComponentConstructorParameters<Props extends {}> {
50+
/**
51+
* An HTMLElement to render to. This option is required.
52+
*/
53+
target: Element;
54+
/**
55+
* A child of `target` to render the component immediately before.
56+
*/
57+
anchor?: Element;
58+
/**
59+
* An object of properties to supply to the component.
60+
*/
61+
props?: Props;
62+
hydrate?: boolean;
63+
intro?: boolean;
64+
$$inline?: boolean;
65+
}
66+
67+
type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
68+
type SvelteComponentConstructor<T, U extends Svelte2TsxComponentConstructorParameters<any>> = new (options: U) => T;
6669

6770
type SvelteAction<U extends any[], El extends any> = (node: El, ...args:U) => {
6871
update?: (...args:U) => void,
@@ -174,7 +177,7 @@ declare function __sveltets_each<T>(
174177

175178
declare function createSvelte2TsxComponent<Props, Events, Slots>(
176179
render: () => {props?: Props, events?: Events, slots?: Slots }
177-
): AConstructorTypeOf<Svelte2TsxComponent<Props, Events, Slots>>;
180+
): SvelteComponentConstructor<Svelte2TsxComponent<Props, Events, Slots>,Svelte2TsxComponentConstructorParameters<Props>>;
178181

179182
declare function __sveltets_unwrapArr<T>(arr: ArrayLike<T>): T
180183
declare function __sveltets_unwrapPromiseLike<T>(promise: PromiseLike<T> | T): T

0 commit comments

Comments
 (0)