From 9e1b74bcd5fa4151f5d1bc02c69fbbfa4762f577 Mon Sep 17 00:00:00 2001 From: edison Date: Fri, 10 Nov 2023 16:00:04 +0800 Subject: [PATCH] fix(compiler-sfc): support resolve extends interface for defineEmits (#8470) close #8465 --- .../__snapshots__/defineEmits.spec.ts.snap | 18 ++++++++++++++++++ .../compileScript/defineEmits.spec.ts | 12 ++++++++++++ .../compiler-sfc/src/script/resolveType.ts | 5 ++++- 3 files changed, 34 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 1e851cbf4df..78a9834d288 100644 --- a/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineEmits.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineEmits.spec.ts.snap @@ -81,6 +81,24 @@ return { emit } })" `; +exports[`defineEmits > w/ type (interface w/ extends) 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: __emit }) { + __expose(); + + const emit = __emit + +return { emit } +} + +})" +`; + exports[`defineEmits > w/ type (interface) 1`] = ` "import { defineComponent as _defineComponent } from 'vue' interface Emits { (e: 'foo' | 'bar'): void } diff --git a/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts b/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts index 13b981db3d7..0d1a41e0f2b 100644 --- a/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/defineEmits.spec.ts @@ -80,6 +80,18 @@ const emit = defineEmits(['a', 'b']) expect(content).toMatch(`emits: ["foo", "bar"]`) }) + test('w/ type (interface w/ extends)', () => { + const { content } = compile(` + + `) + assertCode(content) + expect(content).toMatch(`emits: ["bar", "foo"]`) + }) + test('w/ type (exported interface)', () => { const { content } = compile(`