Infer tuple types like template literal types do #61539
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
π Search Terms
Named Tuples
infer tuple element name
function type parameter names
Function Currying
β Viability Checklist
β Suggestion
Infer tuple types like template literal types do.
Example:
This might be a breaking change to some tuple types infer behavior of existing TypeScript code, but the new behavior is more concrete and more reasonable.
π Motivating Example
Currently, when we try to write types for a function currying utility library (such as
lodash.curry
), the parameter names will be lost in new functions.This feature allows us to get one element of tuple and keep the element name if present.
For more discussion, see #49122 (comment).
π» Use Cases
What do you want to use this for?
Use this for function currying (i.e.
std::bind
inC++
, partial functions inPython
) and keep the corresponding parameter names in new function.What shortcomings exist with current approaches?
Types of bound function created via
Function.prototype.bind
provide the parameter names perfectly, but we cannot useFunction.prototype.bind
to bind parameters skipping those in the front.Library functions like
lodash.curry
can infer the correct parameter type but cannot provide the parameter names. So we may make mistakes when parameter types are the same.What workarounds are you using in the meantime?
No parameter name of original function but generated names like
arg_0
instead.The text was updated successfully, but these errors were encountered: