mirror of https://github.com/vuejs/core.git
fix(runtime-core): correct type inference for PascalCase emits (#11579)
fix vuejs/language-tools#4269
This commit is contained in:
parent
7d700c215d
commit
d7d0371e74
|
@ -906,12 +906,15 @@ describe('emits', () => {
|
||||||
emits: {
|
emits: {
|
||||||
click: (n: number) => typeof n === 'number',
|
click: (n: number) => typeof n === 'number',
|
||||||
input: (b: string) => b.length > 1,
|
input: (b: string) => b.length > 1,
|
||||||
|
Focus: (f: boolean) => !!f,
|
||||||
},
|
},
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
expectType<((n: number) => boolean) | undefined>(props.onClick)
|
expectType<((n: number) => boolean) | undefined>(props.onClick)
|
||||||
expectType<((b: string) => boolean) | undefined>(props.onInput)
|
expectType<((b: string) => boolean) | undefined>(props.onInput)
|
||||||
|
expectType<((f: boolean) => boolean) | undefined>(props.onFocus)
|
||||||
emit('click', 1)
|
emit('click', 1)
|
||||||
emit('input', 'foo')
|
emit('input', 'foo')
|
||||||
|
emit('Focus', true)
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
emit('nope')
|
emit('nope')
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
|
@ -922,6 +925,10 @@ describe('emits', () => {
|
||||||
emit('input')
|
emit('input')
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
emit('input', 1)
|
emit('input', 1)
|
||||||
|
// @ts-expect-error
|
||||||
|
emit('focus')
|
||||||
|
// @ts-expect-error
|
||||||
|
emit('focus', true)
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.$emit('click', 1)
|
this.$emit('click', 1)
|
||||||
|
@ -936,6 +943,10 @@ describe('emits', () => {
|
||||||
this.$emit('input')
|
this.$emit('input')
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
this.$emit('input', 1)
|
this.$emit('input', 1)
|
||||||
|
// @ts-expect-error
|
||||||
|
this.$emit('focus')
|
||||||
|
// @ts-expect-error
|
||||||
|
this.$emit('focus', true)
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
// #3599
|
// #3599
|
||||||
|
@ -954,6 +965,10 @@ describe('emits', () => {
|
||||||
this.$emit('input')
|
this.$emit('input')
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
this.$emit('input', 1)
|
this.$emit('input', 1)
|
||||||
|
// @ts-expect-error
|
||||||
|
this.$emit('focus')
|
||||||
|
// @ts-expect-error
|
||||||
|
this.$emit('focus', true)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -47,15 +47,13 @@ export type EmitsToProps<T extends EmitsOptions | ComponentTypeEmits> =
|
||||||
}
|
}
|
||||||
: T extends ObjectEmitsOptions
|
: T extends ObjectEmitsOptions
|
||||||
? {
|
? {
|
||||||
[K in `on${Capitalize<string & keyof T>}`]?: K extends `on${infer C}`
|
[K in string & keyof T as `on${Capitalize<K>}`]?: (
|
||||||
? (
|
...args: T[K] extends (...args: infer P) => any
|
||||||
...args: T[Uncapitalize<C>] extends (...args: infer P) => any
|
|
||||||
? P
|
? P
|
||||||
: T[Uncapitalize<C>] extends null
|
: T[K] extends null
|
||||||
? any[]
|
? any[]
|
||||||
: never
|
: never
|
||||||
) => any
|
) => any
|
||||||
: never
|
|
||||||
}
|
}
|
||||||
: {}
|
: {}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue