types: support object as props type (#3165)
This commit is contained in:
parent
354966204e
commit
4a965802e8
@ -56,7 +56,7 @@ interface PropOptions<T = any, D = T> {
|
|||||||
export type PropType<T> = PropConstructor<T> | PropConstructor<T>[]
|
export type PropType<T> = PropConstructor<T> | PropConstructor<T>[]
|
||||||
|
|
||||||
type PropConstructor<T = any> =
|
type PropConstructor<T = any> =
|
||||||
| { new (...args: any[]): T & object }
|
| { new (...args: any[]): T & {} }
|
||||||
| { (): T }
|
| { (): T }
|
||||||
| PropMethod<T>
|
| PropMethod<T>
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ describe('object props', () => {
|
|||||||
ggg: 'foo' | 'bar'
|
ggg: 'foo' | 'bar'
|
||||||
ffff: (a: number, b: string) => { a: boolean }
|
ffff: (a: number, b: string) => { a: boolean }
|
||||||
validated?: string
|
validated?: string
|
||||||
|
object?: object
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('defineComponent', () => {
|
describe('defineComponent', () => {
|
||||||
@ -106,7 +107,8 @@ describe('object props', () => {
|
|||||||
type: String,
|
type: String,
|
||||||
// validator requires explicit annotation
|
// validator requires explicit annotation
|
||||||
validator: (val: unknown) => val !== ''
|
validator: (val: unknown) => val !== ''
|
||||||
}
|
},
|
||||||
|
object: Object as PropType<object>
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
return {
|
return {
|
||||||
@ -140,6 +142,7 @@ describe('object props', () => {
|
|||||||
expectType<ExpectedProps['ggg']>(props.ggg)
|
expectType<ExpectedProps['ggg']>(props.ggg)
|
||||||
expectType<ExpectedProps['ffff']>(props.ffff)
|
expectType<ExpectedProps['ffff']>(props.ffff)
|
||||||
expectType<ExpectedProps['validated']>(props.validated)
|
expectType<ExpectedProps['validated']>(props.validated)
|
||||||
|
expectType<ExpectedProps['object']>(props.object)
|
||||||
|
|
||||||
// raw bindings
|
// raw bindings
|
||||||
expectType<Number>(rawBindings.setupA)
|
expectType<Number>(rawBindings.setupA)
|
||||||
@ -263,7 +266,8 @@ describe('object props', () => {
|
|||||||
type: String,
|
type: String,
|
||||||
// validator requires explicit annotation
|
// validator requires explicit annotation
|
||||||
validator: (val: unknown) => val !== ''
|
validator: (val: unknown) => val !== ''
|
||||||
}
|
},
|
||||||
|
object: Object as PropType<object>
|
||||||
},
|
},
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
@ -293,6 +297,7 @@ describe('object props', () => {
|
|||||||
expectType<ExpectedProps['ggg']>(props.ggg)
|
expectType<ExpectedProps['ggg']>(props.ggg)
|
||||||
// expectType<ExpectedProps['ffff']>(props.ffff) // todo fix
|
// expectType<ExpectedProps['ffff']>(props.ffff) // todo fix
|
||||||
expectType<ExpectedProps['validated']>(props.validated)
|
expectType<ExpectedProps['validated']>(props.validated)
|
||||||
|
expectType<ExpectedProps['object']>(props.object)
|
||||||
|
|
||||||
// rawBindings
|
// rawBindings
|
||||||
expectType<Number>(rawBindings.setupA)
|
expectType<Number>(rawBindings.setupA)
|
||||||
|
Loading…
Reference in New Issue
Block a user