浏览代码

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
Herrington Darkholme 5 年之前
父节点
当前提交
6f8bac5fca
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      test-dts/defineComponent.test-d.tsx

+ 6 - 0
test-dts/defineComponent.test-d.tsx

@@ -27,6 +27,7 @@ describe('with object props', () => {
     eee: () => { a: string }
     fff: (a: number, b: string) => { a: boolean }
     hhh: boolean
+    validated?: string
   }
 
   type GT = string & { __brand: unknown }
@@ -75,6 +76,10 @@ describe('with object props', () => {
       hhh: {
         type: Boolean,
         required: true
+      },
+      validated: {
+        type: String,
+        validator: (val: unknown) => val !== ''
       }
     },
     setup(props) {
@@ -92,6 +97,7 @@ describe('with object props', () => {
       expectType<ExpectedProps['eee']>(props.eee)
       expectType<ExpectedProps['fff']>(props.fff)
       expectType<ExpectedProps['hhh']>(props.hhh)
+      expectType<ExpectedProps['validated']>(props.validated)
 
       // @ts-expect-error props should be readonly
       expectError((props.a = 1))