Intersect function type or call signature with a different return type #30351
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Search Terms
Intersect function type with a different return type (Call Signature, Constructor, ConstructorParameters, ReturnType, Signature, FunctionSignature, Parameters, FunctionParameters).
Suggestion
This feature could be implemented in a number of different ways:
(...args: Parameters<T>)
to somehow preserve the call signature (and TSDoc comments) of the original functionT
.CallSignature<T>
and/or the ability to define a return type by itselfReturns<T>
.CallSignature<T> => DifferentReturnType
T & Returns<DifferentReturnType>
.Use Cases
Functional programming, wrapper functions that modify or extend the return type only.
Examples
This is the current function I'm trying to create, but I'm struggling with typing the callback in such a way that I preserve the TSDocs and original call signature of
TFunc
.Unfortunately, I can't even use
ReturnType<wrapper>
in this context. Wish I could!Most importantly, the TSDoc comments should be preserved so that instead of this in vscode:
We get almost the same thing as calling the original function (minus the
foo
part):Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: