Skip to content

Commit 6f8bac5

Browse files
test(types): add prop validator test (#1769)
Due to the limitation of TS, prop validator must be fully annotated refer to microsoft/TypeScript#38623
1 parent a2c6f0c commit 6f8bac5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test-dts/defineComponent.test-d.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('with object props', () => {
2727
eee: () => { a: string }
2828
fff: (a: number, b: string) => { a: boolean }
2929
hhh: boolean
30+
validated?: string
3031
}
3132

3233
type GT = string & { __brand: unknown }
@@ -75,6 +76,10 @@ describe('with object props', () => {
7576
hhh: {
7677
type: Boolean,
7778
required: true
79+
},
80+
validated: {
81+
type: String,
82+
validator: (val: unknown) => val !== ''
7883
}
7984
},
8085
setup(props) {
@@ -92,6 +97,7 @@ describe('with object props', () => {
9297
expectType<ExpectedProps['eee']>(props.eee)
9398
expectType<ExpectedProps['fff']>(props.fff)
9499
expectType<ExpectedProps['hhh']>(props.hhh)
100+
expectType<ExpectedProps['validated']>(props.validated)
95101

96102
// @ts-expect-error props should be readonly
97103
expectError((props.a = 1))

0 commit comments

Comments
 (0)