Skip to content

Commit 4a96580

Browse files
authored
types: support object as props type (#3165)
1 parent 3549662 commit 4a96580

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/runtime-core/src/componentProps.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interface PropOptions<T = any, D = T> {
5656
export type PropType<T> = PropConstructor<T> | PropConstructor<T>[]
5757

5858
type PropConstructor<T = any> =
59-
| { new (...args: any[]): T & object }
59+
| { new (...args: any[]): T & {} }
6060
| { (): T }
6161
| PropMethod<T>
6262

test-dts/component.test-d.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('object props', () => {
3939
ggg: 'foo' | 'bar'
4040
ffff: (a: number, b: string) => { a: boolean }
4141
validated?: string
42+
object?: object
4243
}
4344

4445
describe('defineComponent', () => {
@@ -106,7 +107,8 @@ describe('object props', () => {
106107
type: String,
107108
// validator requires explicit annotation
108109
validator: (val: unknown) => val !== ''
109-
}
110+
},
111+
object: Object as PropType<object>
110112
},
111113
setup(props) {
112114
return {
@@ -140,6 +142,7 @@ describe('object props', () => {
140142
expectType<ExpectedProps['ggg']>(props.ggg)
141143
expectType<ExpectedProps['ffff']>(props.ffff)
142144
expectType<ExpectedProps['validated']>(props.validated)
145+
expectType<ExpectedProps['object']>(props.object)
143146

144147
// raw bindings
145148
expectType<Number>(rawBindings.setupA)
@@ -263,7 +266,8 @@ describe('object props', () => {
263266
type: String,
264267
// validator requires explicit annotation
265268
validator: (val: unknown) => val !== ''
266-
}
269+
},
270+
object: Object as PropType<object>
267271
},
268272

269273
setup() {
@@ -293,6 +297,7 @@ describe('object props', () => {
293297
expectType<ExpectedProps['ggg']>(props.ggg)
294298
// expectType<ExpectedProps['ffff']>(props.ffff) // todo fix
295299
expectType<ExpectedProps['validated']>(props.validated)
300+
expectType<ExpectedProps['object']>(props.object)
296301

297302
// rawBindings
298303
expectType<Number>(rawBindings.setupA)

0 commit comments

Comments
 (0)