Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ type PropConstructor<T = any> =
| { (): T }
| PropMethod<T>

type PropMethod<T, TConstructor = any> = [T] extends [(...args: any) => any] // if is function with args
type PropMethod<T, TConstructor = any> = [T] extends [
((...args: any) => any) | undefined
] // if is function with args, allowing non-required functions
? { new (): TConstructor; (): T; readonly prototype: TConstructor } // Create Function like constructor
: never

Expand Down
3 changes: 3 additions & 0 deletions test-dts/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('with object props', () => {
b: string
e?: Function
h: boolean
j: undefined | (() => string | undefined)
bb: string
bbb: string
bbbb: string | undefined
Expand Down Expand Up @@ -55,6 +56,7 @@ describe('with object props', () => {
},
e: Function,
h: Boolean,
j: Function as PropType<undefined | (() => string | undefined)>,
// default value should infer type and make it non-void
bb: {
default: 'hello'
Expand Down Expand Up @@ -137,6 +139,7 @@ describe('with object props', () => {
expectType<ExpectedProps['b']>(props.b)
expectType<ExpectedProps['e']>(props.e)
expectType<ExpectedProps['h']>(props.h)
expectType<ExpectedProps['j']>(props.j)
expectType<ExpectedProps['bb']>(props.bb)
expectType<ExpectedProps['bbb']>(props.bbb)
expectType<ExpectedProps['bbbb']>(props.bbbb)
Expand Down