Ability to replace return type of function type #39594
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
Suggestion
I would like to be able to replace just the return type of a function with a utility type, like
WithReturn<F, R>
.I'm not 100% sure this is needed, but it seems like using
(...args: Parameters<F>) => R
is not sufficient because any generics inF
are lost.Use Cases
My use case is a utility function that captures the arguments to a function to allow it to be called later.
Examples
Right now there's an error because the generics to
map()
are lost when usingParameters
.Playground: https://www.typescriptlang.org/play/?ssl=13&ssc=1&pln=1&pc=1#code/KYDwDg9gTgLgBAYwgOwM7wCbAGbCnAXjgB4AxOUGYZDVOACgDpmBDKAc1QC44XkBPAJSEAfLwEj62HqWEEx9egCg4cZozaceABTYsAtsCpRUZEUrkKA3irjYArsgQwAlih7YANLc2pvAX0FhAHoAKl46Pn4IuHJQ4IBuJSUkNHh9FjBCEgAVTzgAJUk2KBZ+HgBBKFL+YhyRfOkGFx4cy0L2krLGDLApQSTU9DgsXGrgDABZTOzRvHpegeSAGyM4fCI58anM+gBtAEYAXXz6Frhke30AIzx2gCYlqA0OVCSgA
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: