Skip to content

Commit

Permalink
Fix default export return type (#686)
Browse files Browse the repository at this point in the history
Adjust Svelte2TsxComponent class function creator for better type inference.
  • Loading branch information
firefish5000 committed Nov 25, 2020
1 parent 1521818 commit e72c8c4
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions packages/svelte2tsx/svelte-shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@ declare class Svelte2TsxComponent<
*/
$$slot_def: Slots;
// https://svelte.dev/docs#Client-side_component_API
constructor(options: {
/**
* An HTMLElement to render to. This option is required.
*/
target: Element;
/**
* A child of `target` to render the component immediately before.
*/
anchor?: Element;
/**
* An object of properties to supply to the component.
*/
props?: Props;
hydrate?: boolean;
intro?: boolean;
$$inline?: boolean;
});
constructor(options: Svelte2TsxComponentConstructorParameters<Props>);
/**
* Causes the callback function to be called whenever the component dispatches an event.
* A function is returned that will remove the event listener when called.
Expand All @@ -62,7 +46,26 @@ declare class Svelte2TsxComponent<
$inject_state(): void;
}

type AConstructorTypeOf<T> = new (...args: any[]) => T;
interface Svelte2TsxComponentConstructorParameters<Props extends {}> {
/**
* An HTMLElement to render to. This option is required.
*/
target: Element;
/**
* A child of `target` to render the component immediately before.
*/
anchor?: Element;
/**
* An object of properties to supply to the component.
*/
props?: Props;
hydrate?: boolean;
intro?: boolean;
$$inline?: boolean;
}

type AConstructorTypeOf<T, U extends any[] = any[]> = new (...args: U) => T;
type SvelteComponentConstructor<T, U extends Svelte2TsxComponentConstructorParameters<any>> = new (options: U) => T;

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

declare function createSvelte2TsxComponent<Props, Events, Slots>(
render: () => {props?: Props, events?: Events, slots?: Slots }
): AConstructorTypeOf<Svelte2TsxComponent<Props, Events, Slots>>;
): SvelteComponentConstructor<Svelte2TsxComponent<Props, Events, Slots>,Svelte2TsxComponentConstructorParameters<Props>>;

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

0 comments on commit e72c8c4

Please sign in to comment.