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