From: Aurelius333 <22969541+Aurelius333@users.noreply.github.com> Date: Fri, 14 Aug 2020 21:36:26 +0000 (-0400) Subject: types(runtime-core): make `this` void in emits validator (#1842) X-Git-Tag: v3.0.0-rc.6~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5002ab53d6bf379da6ae4aadc89bbbed31318c6c;p=thirdparty%2Fvuejs%2Fcore.git types(runtime-core): make `this` void in emits validator (#1842) --- diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 72fffe241e..816a49c608 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -106,7 +106,7 @@ export interface ComponentOptionsBase< components?: Record directives?: Record inheritAttrs?: boolean - emits?: E | EE[] + emits?: (E | EE[]) & ThisType // Internal ------------------------------------------------------------------ diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index f7dacfcbe2..94669213ed 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -710,6 +710,17 @@ describe('emits', () => { const instance = {} as ComponentPublicInstance instance.$emit('test', 1) instance.$emit('test') + + // `this` should be void inside of emits validators + defineComponent({ + props: ['bar'], + emits: { + foo(): boolean { + // @ts-expect-error + return this.bar === 3 + } + } + }) }) describe('componentOptions setup should be `SetupContext`', () => {