mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): support resolve extends interface for defineEmits (#8470)
close #8465
This commit is contained in:
parent
2424013059
commit
9e1b74bcd5
|
@ -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`] = `
|
exports[`defineEmits > w/ type (interface) 1`] = `
|
||||||
"import { defineComponent as _defineComponent } from 'vue'
|
"import { defineComponent as _defineComponent } from 'vue'
|
||||||
interface Emits { (e: 'foo' | 'bar'): void }
|
interface Emits { (e: 'foo' | 'bar'): void }
|
||||||
|
|
|
@ -80,6 +80,18 @@ const emit = defineEmits(['a', 'b'])
|
||||||
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
expect(content).toMatch(`emits: ["foo", "bar"]`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('w/ type (interface w/ extends)', () => {
|
||||||
|
const { content } = compile(`
|
||||||
|
<script setup lang="ts">
|
||||||
|
interface Base { (e: 'foo'): void }
|
||||||
|
interface Emits extends Base { (e: 'bar'): void }
|
||||||
|
const emit = defineEmits<Emits>()
|
||||||
|
</script>
|
||||||
|
`)
|
||||||
|
assertCode(content)
|
||||||
|
expect(content).toMatch(`emits: ["bar", "foo"]`)
|
||||||
|
})
|
||||||
|
|
||||||
test('w/ type (exported interface)', () => {
|
test('w/ type (exported interface)', () => {
|
||||||
const { content } = compile(`
|
const { content } = compile(`
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
|
@ -334,12 +334,15 @@ function resolveInterfaceMembers(
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const { props } = resolveTypeElements(ctx, ext, scope)
|
const { props, calls } = resolveTypeElements(ctx, ext, scope)
|
||||||
for (const key in props) {
|
for (const key in props) {
|
||||||
if (!hasOwn(base.props, key)) {
|
if (!hasOwn(base.props, key)) {
|
||||||
base.props[key] = props[key]
|
base.props[key] = props[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (calls) {
|
||||||
|
;(base.calls || (base.calls = [])).push(...calls)
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ctx.error(
|
ctx.error(
|
||||||
`Failed to resolve extends base type.\nIf this previously worked in 3.2, ` +
|
`Failed to resolve extends base type.\nIf this previously worked in 3.2, ` +
|
||||||
|
|
Loading…
Reference in New Issue