Skip to content

Commit

Permalink
fix: relax constraint for ComponentProps
Browse files Browse the repository at this point in the history
`Component` with any props should be allowed to pass in
  • Loading branch information
dummdidumm committed Jun 13, 2024
1 parent 0119f25 commit 15ef157
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-melons-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: relax constraint for `ComponentProps`
2 changes: 1 addition & 1 deletion packages/svelte/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export type ComponentEvents<Comp extends SvelteComponent> =
* </script>
* ```
*/
export type ComponentProps<Comp extends SvelteComponent | Component> =
export type ComponentProps<Comp extends SvelteComponent | Component<any>> =
Comp extends SvelteComponent<infer Props>
? Props
: Comp extends Component<infer Props>
Expand Down
7 changes: 7 additions & 0 deletions packages/svelte/tests/types/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ functionComponentInstance.foo === 'bar';
// @ts-expect-error
functionComponentInstance.foo = 'foo';

const functionComponentProps: ComponentProps<typeof functionComponent> = {
binding: true,
readonly: 'foo',
// @ts-expect-error
prop: 1
};

mount(functionComponent, {
target: null as any as Document | Element | ShadowRoot,
props: {
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ declare module 'svelte' {
* </script>
* ```
*/
export type ComponentProps<Comp extends SvelteComponent | Component> =
export type ComponentProps<Comp extends SvelteComponent | Component<any>> =
Comp extends SvelteComponent<infer Props>
? Props
: Comp extends Component<infer Props>
Expand Down

0 comments on commit 15ef157

Please sign in to comment.