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
One has to create extra functions as a workaround, just to get a typehint for a variable:
// A workaroundfunctiongetValue<T>() {vara : Treturn{a: a}}functiongetValue_number(){// Extra function workaround just to avoid template syntax in typeof!returngetValue<number>()}varvalue : ReturnType<typeofgetValue_number>// ...value=getValue<number>()// assigned latervalue// { a: number } - OK
🔍 Search Terms
typeof generic function
✅ Viability Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
The text was updated successfully, but these errors were encountered:
brandon942
changed the title
typeof generic function with a specific template type
typeof generic function with a specific template type should be possible
Jan 21, 2022
I'm not sure what distinguishes this, #40542, and #37181
Probably the expected operator precedence of typeof.
This opened issue focuses on the simpler case for which there is even a workaround. Defining a concrete type from a referenced generic function.
I don't see a workaround for the template type version.
Suggestion
⭐ Suggestion
Related to #37181 but even simpler - have a concrete type instead of a template type.
I wonder how this simple thing is not possible.
💻 Use Cases
Currently it is impossible to have a variable be of a specific type that involves a generic function.
One has to create extra functions as a workaround, just to get a typehint for a variable:
🔍 Search Terms
typeof generic function
✅ Viability Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: