File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -188,14 +188,31 @@ export type ComponentEvents<Comp extends SvelteComponent> =
188
188
Comp extends SvelteComponent < any , infer Events > ? Events : never ;
189
189
190
190
/**
191
- * Convenience type to get the props the given component expects. Example:
192
- * ```html
193
- * <script lang="ts">
194
- * import type { ComponentProps } from 'svelte';
195
- * import Component from './Component.svelte';
191
+ * Convenience type to get the props the given component expects.
196
192
*
197
- * const props: ComponentProps<Component> = { foo: 'bar' }; // Errors if these aren't the correct props
198
- * </script>
193
+ * Example: Ensure a variable contains the props expected by `MyComponent`:
194
+ *
195
+ * ```ts
196
+ * import type { ComponentProps } from 'svelte';
197
+ * import MyComponent from './MyComponent.svelte';
198
+ *
199
+ * // Errors if these aren't the correct props expected by MyComponent.
200
+ * const props: ComponentProps<MyComponent> = { foo: 'bar' };
201
+ * ```
202
+ *
203
+ * Example: A function that accepts some component and infers the type of its props:
204
+ *
205
+ * ```ts
206
+ * import type { Component, ComponentProps } from 'svelte';
207
+ * import MyComponent from './MyComponent.svelte';
208
+ *
209
+ * function withProps<TComponent extends Component<any>>(
210
+ * component: TComponent,
211
+ * props: ComponentProps<TComponent>
212
+ * ) {};
213
+ *
214
+ * // Errors if the second argument is not the correct props expected by the component in the first argument.
215
+ * withProps(MyComponent, { foo: 'bar' });
199
216
* ```
200
217
*/
201
218
export type ComponentProps < Comp extends SvelteComponent | Component < any > > =
You can’t perform that action at this time.
0 commit comments