feat(sfc): add defineEmits and deprecate defineEmit (#3725)
This commit is contained in:
committed by
GitHub
parent
6b6d566861
commit
a137da8a9f
@@ -2,6 +2,7 @@ import {
|
||||
expectType,
|
||||
defineProps,
|
||||
defineEmit,
|
||||
defineEmits,
|
||||
useContext,
|
||||
Slots,
|
||||
describe
|
||||
@@ -49,8 +50,8 @@ describe('defineProps w/ runtime declaration', () => {
|
||||
props2.baz
|
||||
})
|
||||
|
||||
describe('defineEmit w/ type declaration', () => {
|
||||
const emit = defineEmit<(e: 'change') => void>()
|
||||
describe('defineEmits w/ type declaration', () => {
|
||||
const emit = defineEmits<(e: 'change') => void>()
|
||||
emit('change')
|
||||
// @ts-expect-error
|
||||
emit()
|
||||
@@ -58,7 +59,7 @@ describe('defineEmit w/ type declaration', () => {
|
||||
emit('bar')
|
||||
|
||||
type Emits = { (e: 'foo' | 'bar'): void; (e: 'baz', id: number): void }
|
||||
const emit2 = defineEmit<Emits>()
|
||||
const emit2 = defineEmits<Emits>()
|
||||
|
||||
emit2('foo')
|
||||
emit2('bar')
|
||||
@@ -67,8 +68,8 @@ describe('defineEmit w/ type declaration', () => {
|
||||
emit2('baz')
|
||||
})
|
||||
|
||||
describe('defineEmit w/ runtime declaration', () => {
|
||||
const emit = defineEmit({
|
||||
describe('defineEmits w/ runtime declaration', () => {
|
||||
const emit = defineEmits({
|
||||
foo: () => {},
|
||||
bar: null
|
||||
})
|
||||
@@ -77,13 +78,24 @@ describe('defineEmit w/ runtime declaration', () => {
|
||||
// @ts-expect-error
|
||||
emit('baz')
|
||||
|
||||
const emit2 = defineEmit(['foo', 'bar'])
|
||||
const emit2 = defineEmits(['foo', 'bar'])
|
||||
emit2('foo')
|
||||
emit2('bar', 123)
|
||||
// @ts-expect-error
|
||||
emit2('baz')
|
||||
})
|
||||
|
||||
describe('deprecated defineEmit', () => {
|
||||
const emit = defineEmit({
|
||||
foo: () => {},
|
||||
bar: null
|
||||
})
|
||||
emit('foo')
|
||||
emit('bar', 123)
|
||||
// @ts-expect-error
|
||||
emit('baz')
|
||||
})
|
||||
|
||||
describe('useContext', () => {
|
||||
const { attrs, emit, slots } = useContext()
|
||||
expectType<Record<string, unknown>>(attrs)
|
||||
|
||||
Reference in New Issue
Block a user