]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
types(runtime-core): make `this` void in emits validator (#1842)
authorAurelius333 <22969541+Aurelius333@users.noreply.github.com>
Fri, 14 Aug 2020 21:36:26 +0000 (17:36 -0400)
committerGitHub <noreply@github.com>
Fri, 14 Aug 2020 21:36:26 +0000 (17:36 -0400)
packages/runtime-core/src/componentOptions.ts
test-dts/defineComponent.test-d.tsx

index 72fffe241e8deca896e398acff294e0d63c6e151..816a49c608ebbbb16240117f46a42e2169424611 100644 (file)
@@ -106,7 +106,7 @@ export interface ComponentOptionsBase<
   components?: Record<string, PublicAPIComponent>
   directives?: Record<string, Directive>
   inheritAttrs?: boolean
-  emits?: E | EE[]
+  emits?: (E | EE[]) & ThisType<void>
 
   // Internal ------------------------------------------------------------------
 
index f7dacfcbe21e93e8551f15fabb8f9bde36462be3..94669213edddb8949f63da7bb23d2e3c0938c55b 100644 (file)
@@ -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`', () => {