Skip to content

Commit

Permalink
fix(types): fix tsx emit-mapped handler return type (#4290)
Browse files Browse the repository at this point in the history
fix #4288
  • Loading branch information
webfansplz authored Aug 11, 2021
1 parent 380608b commit 1ce34e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ export type EmitsToProps<T extends EmitsOptions> = T extends string[]
`on${Capitalize<string & keyof T>}`]?: K extends `on${infer C}`
? T[Uncapitalize<C>] extends null
? (...args: any[]) => any
: T[Uncapitalize<C>]
: (
...args: T[Uncapitalize<C>] extends (...args: infer P) => any
? P
: never
) => any
: never
}
: {}
Expand Down
27 changes: 27 additions & 0 deletions test-dts/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,33 @@ describe('emits', () => {
}
})

// with tsx
const Component = defineComponent({
emits: {
click: (n: number) => typeof n === 'number'
},
setup(props, { emit }) {
expectType<((n: number) => any) | undefined>(props.onClick)
emit('click', 1)
// @ts-expect-error
expectError(emit('click'))
// @ts-expect-error
expectError(emit('click', 'foo'))
}
})

defineComponent({
render() {
return (
<Component
onClick={(n: number) => {
return n + 1
}}
/>
)
}
})

// without emits
defineComponent({
setup(props, { emit }) {
Expand Down

0 comments on commit 1ce34e2

Please sign in to comment.