]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(types): add prop validator test (#1769)
authorHerrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com>
Fri, 14 Aug 2020 21:40:41 +0000 (05:40 +0800)
committerGitHub <noreply@github.com>
Fri, 14 Aug 2020 21:40:41 +0000 (17:40 -0400)
Due to the limitation of TS, prop validator must be fully annotated
refer to https://github.com/microsoft/TypeScript/issues/38623

test-dts/defineComponent.test-d.tsx

index 94669213edddb8949f63da7bb23d2e3c0938c55b..b65ca88ae89d982f0f95e08a7bda1e9cebea942d 100644 (file)
@@ -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))