From: Aurelius333 <22969541+Aurelius333@users.noreply.github.com> Date: Tue, 18 Aug 2020 15:25:55 +0000 (-0400) Subject: types(runtime-core): make `this` void in prop validators and prop default factories... X-Git-Tag: v3.0.0-rc.6~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a88895b5da63fbbda8d189d16e174f8c0da7bcee;p=thirdparty%2Fvuejs%2Fcore.git types(runtime-core): make `this` void in prop validators and prop default factories (#1867) --- diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 816a49c608..9c9e2c13a7 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -217,7 +217,7 @@ export type ComponentOptionsWithObjectProps< EE extends string = string, Props = Readonly> > = ComponentOptionsBase & { - props: PropsOptions + props: PropsOptions & ThisType } & ThisType< CreateComponentPublicInstance< Props, diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 1dbb192914..41b26f266a 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -210,6 +210,27 @@ describe('with object props', () => { ) // @ts-expect-error expectError() + + // `this` should be void inside of prop validators and prop default factories + defineComponent({ + props: { + myProp: { + type: Number, + validator(val: unknown): boolean { + // @ts-expect-error + return val !== this.otherProp + }, + default(): number { + // @ts-expect-error + return this.otherProp + 1 + } + }, + otherProp: { + type: Number, + required: true + } + } + }) }) // describe('type inference w/ optional props declaration', () => {