Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: relax ComponentPublicInstanceConstructor type for class components #1943

Merged
merged 4 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export type ComponentPublicInstanceConstructor<
__isFragment?: never
__isTeleport?: never
__isSuspense?: never
new (): T
new (...args: never[]): T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using any[] passes the tests - which I think is fine.

}

export type CreateComponentPublicInstance<
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface Constructor<P = any> {
__isFragment?: never
__isTeleport?: never
__isSuspense?: never
new (): { $props: P }
new (...args: never[]): { $props: P }
}

// The following is a series of overloads for providing props validation of
Expand Down
10 changes: 10 additions & 0 deletions test-dts/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,16 @@ describe('defineComponent', () => {
components: { comp }
})
})

test('should accept class components with receiving constructor arguments', () => {
class Comp {
static __vccOpts = {}
constructor(_props: { foo: string }) {}
}
defineComponent({
components: { Comp }
})
})
})

describe('emits', () => {
Expand Down