diff --git a/generate-type-definitions.js b/generate-type-definitions.js index 00b079eb5d..d8f6e9f826 100644 --- a/generate-type-definitions.js +++ b/generate-type-definitions.js @@ -16,7 +16,7 @@ function modify(path, modifyFn) { modify( 'types/runtime/index.d.ts', - content => content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps') + content => content.replace('SvelteComponentTyped', 'SvelteComponentTyped, ComponentType, ComponentConstructorOptions, ComponentProps, ComponentEvents') ); modify( 'types/compiler/index.d.ts', diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 5b00e7dc5b..df40f94230 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -264,18 +264,18 @@ export class SvelteComponentTyped< /** * Convenience type to get the type of a Svelte component. Useful for example in combination with * dynamic components using ``. - * + * * Example: * ```html * - * + * * * * ``` @@ -292,7 +292,7 @@ export type ComponentType * import type { ComponentProps } from 'svelte'; * import Component from './Component.svelte'; - * + * * const props: ComponentProps = { foo: 'bar' }; // Errors if these aren't the correct props * * ``` @@ -301,6 +301,24 @@ export type ComponentProps = Component extend ? Props : never; +/** + * Convenience type to get the events the given component expects. Example: + * ```html + * + * + * + * ``` + */ +export type ComponentEvents = + Component extends SvelteComponentTyped ? Events : never; + export function loop_guard(timeout) { const start = Date.now(); return () => {