fix(compiler-sfc): support proper type arguments for defineEmit helper

fix #2874
This commit is contained in:
Evan You
2021-03-29 16:38:07 -04:00
parent 2793bc0918
commit bb8cdcad9f
4 changed files with 40 additions and 14 deletions

View File

@@ -532,6 +532,18 @@ const emit = defineEmit(['a', 'b'])
test('defineEmit w/ type (union)', () => {
const type = `((e: 'foo' | 'bar') => void) | ((e: 'baz', id: number) => void)`
expect(() =>
compile(`
<script setup lang="ts">
import { defineEmit } from 'vue'
const emit = defineEmit<${type}>()
</script>
`)
).toThrow()
})
test('defineEmit w/ type (type literal w/ call signatures)', () => {
const type = `{(e: 'foo' | 'bar'): void; (e: 'baz', id: number): void;}`
const { content } = compile(`
<script setup lang="ts">
import { defineEmit } from 'vue'