🔎 Search Terms
ReturnType, generic, default
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
No response
💻 Code
const func = <Return = string>(): Return {
//
}
type ShouldBeNumber = ReturnType<typeof func<number>>; // number
type ShouldBeString = ReturnType<typeof func>; // unknown
🙁 Actual behavior
ReturnType returns unknown.
🙂 Expected behavior
ReturnType returns default type.
Additional information about the issue
This was encountered when trying to write this kind of function:
const invoker = <Endpoint extends (...args: any) => any>(endpoint: Endpoint, ...parameters: Parameters<Endpoint>): ReturnType<Endpoint> {
// Perform some logic before endpoint function is called
return endpoint(...parameters);
}