Skip to content

Commit

Permalink
fix(types): fix on* props incorrect type for TS 4.7 (vuejs#6216)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikax authored Jul 6, 2022
1 parent 17c50ce commit 8dcb6c7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function defineComponent<
M extends MethodOptions = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
E extends EmitsOptions = {},
EE extends string = string
>(
options: ComponentOptionsWithoutProps<
Expand All @@ -130,7 +130,7 @@ export function defineComponent<
M extends MethodOptions = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = Record<string, any>,
E extends EmitsOptions = {},
EE extends string = string
>(
options: ComponentOptionsWithArrayProps<
Expand Down Expand Up @@ -168,7 +168,7 @@ export function defineComponent<
M extends MethodOptions = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = Record<string, any>,
E extends EmitsOptions = {},
EE extends string = string
>(
options: ComponentOptionsWithObjectProps<
Expand Down
33 changes: 32 additions & 1 deletion test-dts/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,38 @@ describe('should allow to assign props', () => {
expectType<JSX.Element>(<Parent {...child.$props} />)
})

// #6052
describe('prop starting with `on*` is broken', () => {
defineComponent({
props: {
onX: {
type: Function as PropType<(a: 1) => void>,
required: true
}
},
setup(props) {
expectType<(a: 1) => void>(props.onX)
props.onX(1)
}
})

defineComponent({
props: {
onX: {
type: Function as PropType<(a: 1) => void>,
required: true
}
},
emits: {
test: (a: 1) => true
},
setup(props) {
expectType<(a: 1) => void>(props.onX)
expectType<undefined | ((a: 1) => any)>(props.onTest)
}
})
})

// check if defineComponent can be exported
export default {
// function components
Expand Down Expand Up @@ -1209,5 +1241,4 @@ declare const MyButton: DefineComponent<
Readonly<ExtractPropTypes<{}>>,
{}
>

;<MyButton class="x" />

0 comments on commit 8dcb6c7

Please sign in to comment.