Skip to content

Commit 8dcb6c7

Browse files
authored
fix(types): fix on* props incorrect type for TS 4.7 (#6216)
fix #6052
1 parent 17c50ce commit 8dcb6c7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

packages/runtime-core/src/apiDefineComponent.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function defineComponent<
103103
M extends MethodOptions = {},
104104
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
105105
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
106-
E extends EmitsOptions = EmitsOptions,
106+
E extends EmitsOptions = {},
107107
EE extends string = string
108108
>(
109109
options: ComponentOptionsWithoutProps<
@@ -130,7 +130,7 @@ export function defineComponent<
130130
M extends MethodOptions = {},
131131
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
132132
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
133-
E extends EmitsOptions = Record<string, any>,
133+
E extends EmitsOptions = {},
134134
EE extends string = string
135135
>(
136136
options: ComponentOptionsWithArrayProps<
@@ -168,7 +168,7 @@ export function defineComponent<
168168
M extends MethodOptions = {},
169169
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
170170
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
171-
E extends EmitsOptions = Record<string, any>,
171+
E extends EmitsOptions = {},
172172
EE extends string = string
173173
>(
174174
options: ComponentOptionsWithObjectProps<

test-dts/defineComponent.test-d.tsx

+32-1
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,38 @@ describe('should allow to assign props', () => {
11631163
expectType<JSX.Element>(<Parent {...child.$props} />)
11641164
})
11651165

1166+
// #6052
1167+
describe('prop starting with `on*` is broken', () => {
1168+
defineComponent({
1169+
props: {
1170+
onX: {
1171+
type: Function as PropType<(a: 1) => void>,
1172+
required: true
1173+
}
1174+
},
1175+
setup(props) {
1176+
expectType<(a: 1) => void>(props.onX)
1177+
props.onX(1)
1178+
}
1179+
})
1180+
1181+
defineComponent({
1182+
props: {
1183+
onX: {
1184+
type: Function as PropType<(a: 1) => void>,
1185+
required: true
1186+
}
1187+
},
1188+
emits: {
1189+
test: (a: 1) => true
1190+
},
1191+
setup(props) {
1192+
expectType<(a: 1) => void>(props.onX)
1193+
expectType<undefined | ((a: 1) => any)>(props.onTest)
1194+
}
1195+
})
1196+
})
1197+
11661198
// check if defineComponent can be exported
11671199
export default {
11681200
// function components
@@ -1209,5 +1241,4 @@ declare const MyButton: DefineComponent<
12091241
Readonly<ExtractPropTypes<{}>>,
12101242
{}
12111243
>
1212-
12131244
;<MyButton class="x" />

0 commit comments

Comments
 (0)