From b01e0792baf447bf28abe3b4081fd52c2b0f523d Mon Sep 17 00:00:00 2001 From: daiwei Date: Thu, 1 Jun 2023 08:53:56 +0800 Subject: [PATCH] fix(compiler-sfc): support resolve extends interface for defineEmits --- .../__snapshots__/defineEmits.spec.ts.snap | 18 ++++++++++++++++++ .../compileScript/defineEmits.spec.ts | 12 ++++++++++++ .../compiler-sfc/src/script/resolveType.ts | 9 ++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineEmits.spec.ts.snap b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineEmits.spec.ts.snap index a8bd930fbbc..1d0f8464307 100644 --- a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineEmits.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineEmits.spec.ts.snap @@ -75,6 +75,24 @@ export default /*#__PURE__*/_defineComponent({ +return { emit } +} + +})" +`; + +exports[`defineEmits > w/ type (interface w/ entends) 1`] = ` +"import { defineComponent as _defineComponent } from 'vue' +interface Base { (e: 'foo'): void } + interface Emits extends Base { (e: 'bar'): void } + +export default /*#__PURE__*/_defineComponent({ + emits: [\\"bar\\", \\"foo\\"], + setup(__props, { expose: __expose, emit }) { + __expose(); + + + return { emit } } diff --git a/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts b/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts index c5d2900a4e7..2fc8923f879 100644 --- a/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts @@ -78,6 +78,18 @@ const emit = defineEmits(['a', 'b']) expect(content).toMatch(`emits: ["foo", "bar"]`) }) + test('w/ type (interface w/ entends)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emits: ["bar", "foo"]`) + }) + test('w/ type (exported interface)', () => { const { content } = compile(`