test(types): add prop validator test (#1769)
Due to the limitation of TS, prop validator must be fully annotated refer to https://github.com/microsoft/TypeScript/issues/38623
This commit is contained in:
parent
a2c6f0c8c7
commit
6f8bac5fca
@ -27,6 +27,7 @@ describe('with object props', () => {
|
|||||||
eee: () => { a: string }
|
eee: () => { a: string }
|
||||||
fff: (a: number, b: string) => { a: boolean }
|
fff: (a: number, b: string) => { a: boolean }
|
||||||
hhh: boolean
|
hhh: boolean
|
||||||
|
validated?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
type GT = string & { __brand: unknown }
|
type GT = string & { __brand: unknown }
|
||||||
@ -75,6 +76,10 @@ describe('with object props', () => {
|
|||||||
hhh: {
|
hhh: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
validated: {
|
||||||
|
type: String,
|
||||||
|
validator: (val: unknown) => val !== ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
@ -92,6 +97,7 @@ describe('with object props', () => {
|
|||||||
expectType<ExpectedProps['eee']>(props.eee)
|
expectType<ExpectedProps['eee']>(props.eee)
|
||||||
expectType<ExpectedProps['fff']>(props.fff)
|
expectType<ExpectedProps['fff']>(props.fff)
|
||||||
expectType<ExpectedProps['hhh']>(props.hhh)
|
expectType<ExpectedProps['hhh']>(props.hhh)
|
||||||
|
expectType<ExpectedProps['validated']>(props.validated)
|
||||||
|
|
||||||
// @ts-expect-error props should be readonly
|
// @ts-expect-error props should be readonly
|
||||||
expectError((props.a = 1))
|
expectError((props.a = 1))
|
||||||
|
Loading…
Reference in New Issue
Block a user