Merge branch 'sveltecomponentconstructor-type' of https://github.com/dummdidumm/svelte into sveltecomponentconstructor-type

pull/6770/head
Simon 4 years ago
commit e38f5b0ad4

@ -263,31 +263,31 @@ export class SvelteComponentTyped<
/** /**
* Convenience type to get the type of a Svelte component. Useful for example in combination with * Convenience type to get the type of a Svelte component. Useful for example in combination with
* dynamic components and `<svelte:element>`. * dynamic components using `<svelte:component>`.
* *
* Example: * Example:
* ```html * ```html
* <script lang="ts"> * <script lang="ts">
* import { ComponentType, SvelteComponentTyped } from 'svelte'; * import type { ComponentType, SvelteComponentTyped } from 'svelte';
* import Component1 from './Component1.svelte'; * import Component1 from './Component1.svelte';
* import Component2 from './Component2.svelte'; * import Component2 from './Component2.svelte';
* *
* const component: ComponentType = someLogic() ? Component1 : Component2; * const component: ComponentType = someLogic() ? Component1 : Component2;
* const componentOfCertainSubType: ComponentType<SvelteComponentTyped<{needsThisProp: string}>> = someLogic() ? Component1 : Component2; * const componentOfCertainSubType: ComponentType<SvelteComponentTyped<{ needsThisProp: string }>> = someLogic() ? Component1 : Component2;
* </script> * </script>
* *
* <svelte:element this={component} /> * <svelte:component this={component} />
* <svelte:element this={componentOfCertainSubType} needsThisProp="hello" /> * <svelte:component this={componentOfCertainSubType} needsThisProp="hello" />
* ``` * ```
*/ */
export type ComponentType<Component extends SvelteComponentTyped = SvelteComponentTyped<any, any, any>> = export type ComponentType<Component extends SvelteComponentTyped = SvelteComponentTyped<any, any, any>> =
new (p: ComponentConstructorOptions<Component extends SvelteComponentTyped<infer Props, any, any> ? Props : any>) => Component; new (p: ComponentConstructorOptions<Component extends SvelteComponentTyped<infer Props, any, any> ? Props : any>) => Component;
/** /**
* Convenience type to get the properties the given component expects. Example: * Convenience type to get the props the given component expects. Example:
* ```html * ```html
* <script lang="ts"> * <script lang="ts">
* import { ComponentProps } from 'svelte'; * import type { ComponentProps } from 'svelte';
* import Component from './Component.svelte'; * import Component from './Component.svelte';
* *
* const props: ComponentProps<Component> = { foo: 'bar' }; // Errors if these aren't the correct props * const props: ComponentProps<Component> = { foo: 'bar' }; // Errors if these aren't the correct props

Loading…
Cancel
Save