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