@@ -264,18 +264,18 @@ export class SvelteComponentTyped<
264
264
/**
265
265
* Convenience type to get the type of a Svelte component. Useful for example in combination with
266
266
* dynamic components using `<svelte:component>`.
267
- *
267
+ *
268
268
* Example:
269
269
* ```html
270
270
* <script lang="ts">
271
271
* import type { ComponentType, SvelteComponentTyped } from 'svelte';
272
272
* import Component1 from './Component1.svelte';
273
273
* import Component2 from './Component2.svelte';
274
- *
274
+ *
275
275
* const component: ComponentType = someLogic() ? Component1 : Component2;
276
276
* const componentOfCertainSubType: ComponentType<SvelteComponentTyped<{ needsThisProp: string }>> = someLogic() ? Component1 : Component2;
277
277
* </script>
278
- *
278
+ *
279
279
* <svelte:component this={component} />
280
280
* <svelte:component this={componentOfCertainSubType} needsThisProp="hello" />
281
281
* ```
@@ -292,7 +292,7 @@ export type ComponentType<Component extends SvelteComponentTyped = SvelteCompone
292
292
* <script lang="ts">
293
293
* import type { ComponentProps } from 'svelte';
294
294
* import Component from './Component.svelte';
295
- *
295
+ *
296
296
* const props: ComponentProps<Component> = { foo: 'bar' }; // Errors if these aren't the correct props
297
297
* </script>
298
298
* ```
@@ -301,6 +301,24 @@ export type ComponentProps<Component extends SvelteComponent> = Component extend
301
301
? Props
302
302
: never ;
303
303
304
+ /**
305
+ * Convenience type to get the events the given component expects. Example:
306
+ * ```html
307
+ * <script lang="ts">
308
+ * import type { ComponentEvents } from 'svelte';
309
+ * import Component from './Component.svelte';
310
+ *
311
+ * function handleCloseEvent(event: ComponentEvents<Component>['close']) {
312
+ * console.log(event.detail);
313
+ * }
314
+ * </script>
315
+ *
316
+ * <Component on:close={handleCloseEvent} />
317
+ * ```
318
+ */
319
+ export type ComponentEvents < Component extends SvelteComponent > =
320
+ Component extends SvelteComponentTyped < any , infer Events > ? Events : never ;
321
+
304
322
export function loop_guard ( timeout ) {
305
323
const start = Date . now ( ) ;
306
324
return ( ) => {
0 commit comments