Skip to content

Commit

Permalink
types: support object as props type (#3165)
Browse files Browse the repository at this point in the history
  • Loading branch information
HcySunYang authored Feb 24, 2021
1 parent 3549662 commit 4a96580
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface PropOptions<T = any, D = T> {
export type PropType<T> = PropConstructor<T> | PropConstructor<T>[]

type PropConstructor<T = any> =
| { new (...args: any[]): T & object }
| { new (...args: any[]): T & {} }
| { (): T }
| PropMethod<T>

Expand Down
9 changes: 7 additions & 2 deletions test-dts/component.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('object props', () => {
ggg: 'foo' | 'bar'
ffff: (a: number, b: string) => { a: boolean }
validated?: string
object?: object
}

describe('defineComponent', () => {
Expand Down Expand Up @@ -106,7 +107,8 @@ describe('object props', () => {
type: String,
// validator requires explicit annotation
validator: (val: unknown) => val !== ''
}
},
object: Object as PropType<object>
},
setup(props) {
return {
Expand Down Expand Up @@ -140,6 +142,7 @@ describe('object props', () => {
expectType<ExpectedProps['ggg']>(props.ggg)
expectType<ExpectedProps['ffff']>(props.ffff)
expectType<ExpectedProps['validated']>(props.validated)
expectType<ExpectedProps['object']>(props.object)

// raw bindings
expectType<Number>(rawBindings.setupA)
Expand Down Expand Up @@ -263,7 +266,8 @@ describe('object props', () => {
type: String,
// validator requires explicit annotation
validator: (val: unknown) => val !== ''
}
},
object: Object as PropType<object>
},

setup() {
Expand Down Expand Up @@ -293,6 +297,7 @@ describe('object props', () => {
expectType<ExpectedProps['ggg']>(props.ggg)
// expectType<ExpectedProps['ffff']>(props.ffff) // todo fix
expectType<ExpectedProps['validated']>(props.validated)
expectType<ExpectedProps['object']>(props.object)

// rawBindings
expectType<Number>(rawBindings.setupA)
Expand Down

0 comments on commit 4a96580

Please sign in to comment.