Skip to content

Commit d7d0371

Browse files
authored
fix(runtime-core): correct type inference for PascalCase emits (#11579)
fix vuejs/language-tools#4269
1 parent 7d700c2 commit d7d0371

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

packages-private/dts-test/defineComponent.test-d.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -906,12 +906,15 @@ describe('emits', () => {
906906
emits: {
907907
click: (n: number) => typeof n === 'number',
908908
input: (b: string) => b.length > 1,
909+
Focus: (f: boolean) => !!f,
909910
},
910911
setup(props, { emit }) {
911912
expectType<((n: number) => boolean) | undefined>(props.onClick)
912913
expectType<((b: string) => boolean) | undefined>(props.onInput)
914+
expectType<((f: boolean) => boolean) | undefined>(props.onFocus)
913915
emit('click', 1)
914916
emit('input', 'foo')
917+
emit('Focus', true)
915918
// @ts-expect-error
916919
emit('nope')
917920
// @ts-expect-error
@@ -922,6 +925,10 @@ describe('emits', () => {
922925
emit('input')
923926
// @ts-expect-error
924927
emit('input', 1)
928+
// @ts-expect-error
929+
emit('focus')
930+
// @ts-expect-error
931+
emit('focus', true)
925932
},
926933
created() {
927934
this.$emit('click', 1)
@@ -936,6 +943,10 @@ describe('emits', () => {
936943
this.$emit('input')
937944
// @ts-expect-error
938945
this.$emit('input', 1)
946+
// @ts-expect-error
947+
this.$emit('focus')
948+
// @ts-expect-error
949+
this.$emit('focus', true)
939950
},
940951
mounted() {
941952
// #3599
@@ -954,6 +965,10 @@ describe('emits', () => {
954965
this.$emit('input')
955966
// @ts-expect-error
956967
this.$emit('input', 1)
968+
// @ts-expect-error
969+
this.$emit('focus')
970+
// @ts-expect-error
971+
this.$emit('focus', true)
957972
})
958973
},
959974
})

packages/runtime-core/src/componentEmits.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ export type EmitsToProps<T extends EmitsOptions | ComponentTypeEmits> =
4747
}
4848
: T extends ObjectEmitsOptions
4949
? {
50-
[K in `on${Capitalize<string & keyof T>}`]?: K extends `on${infer C}`
51-
? (
52-
...args: T[Uncapitalize<C>] extends (...args: infer P) => any
53-
? P
54-
: T[Uncapitalize<C>] extends null
55-
? any[]
56-
: never
57-
) => any
58-
: never
50+
[K in string & keyof T as `on${Capitalize<K>}`]?: (
51+
...args: T[K] extends (...args: infer P) => any
52+
? P
53+
: T[K] extends null
54+
? any[]
55+
: never
56+
) => any
5957
}
6058
: {}
6159

0 commit comments

Comments
 (0)