You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: enhance type inference for useEmitAsProps and useForwardPropsEmits (#2643)
* feat(core): add typed return values for useEmitAsProps
The useEmitAsProps function now properly types the returned props based on
the emit function signature, including support for function overloads. This
improves TypeScript type inference and provides better IDE autocomplete for
event handlers.
- Added generic type parameter Fn for the emit function type
- Added type utilities for handling function overloads
- Result type now accurately reflects the event handler signatures
* feat(core): enhance type inference for useForwardPropsEmits
Exported WithOptionalBooleans type utility and added function overloads
to properly infer ComputedRef return types based on emit parameter.
The overloads accurately reflect whether emits are converted to props.
* fix(core): correct CamelCase type conversion for kebab-case strings
* fix(core): resolve ToEmit type inference for overloaded functions
The previous implementation directly pattern-matched on function signatures,
which only works for non-overloaded functions. This change utilizes
OverloadSignatureTuple to correctly extract and match overload signatures
against the expected emit name, enabling proper type inference for
functions with multiple overloads.
* docs(core): update ExtendSignature @ts-expect-error explanation
Expand the comment to clarify that ExtendSignature intentionally extends
generic type T to inherit all overloads for the recursive overload walking
algorithm, and warn against removing the suppression as it would break
the recursion/bottoming-out logic.
* refactor(core): rename UnionToOptional to MergeUnion utility type
Rename the UnionToOptional type to MergeUnion to better reflect its
purpose of converting a union of function signatures into a single
merged object type with optional properties. The implementation remains
unchanged, only the type name is updated for improved clarity and
maintainability.
* refactor(core): replace Function with AnyFn for improved type inference
Replace the generic `Function` type with `AnyFn` from `@vueuse/shared` across
`useEmitAsProps` and `useForwardPropsEmits` utilities. This change improves type
inference and type safety by using a more specific function type constraint instead
of the overly broad `Function` type, which provides better IDE autocompletion and
catches more type errors at compile time. The runtime behavior remains unchanged.
* refactor(core): simplify useEmitAsProps type definitions
- add package-private overload types from @vue/shared package
- simplify utility types
* fix(core): export EmitAsProps type from shared index
* fix(core): improve camelCase type conversion to handle all word characters
* test(core): add type tests for useEmitAsProps and useForwardPropsEmits
Compile-time assertions (validated by vue-tsc via tsconfig.check.json) that
lock in the new emit type inference: overloaded, single, and loose emit
signatures, plus the props+emit merge of useForwardPropsEmits. The file is
type-checked by the existing build job but not run by Vitest or bundled.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Alexei Myshkouski <am@samplify.org>
Co-authored-by: zernonia <zernonia@gmail.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments