From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Fri, 14 Aug 2020 21:40:41 +0000 (+0800) Subject: test(types): add prop validator test (#1769) X-Git-Tag: v3.0.0-rc.6~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f8bac5fcaf8539fca775067c25ea49673eec1b9;p=thirdparty%2Fvuejs%2Fcore.git 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 --- diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 94669213ed..b65ca88ae8 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/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(props.eee) expectType(props.fff) expectType(props.hhh) + expectType(props.validated) // @ts-expect-error props should be readonly expectError((props.a = 1))