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
{{ message }}
Repository navigation
Mapping a generic type should again result in a generic typeΒ #48036
Performing type mapping on a generic type should result in a new generic type with that mapping applied, rather than a concrete type with unknown in place of generics.
π Motivating Example
Consider the following utility type Async<T>. It takes an arbitrary function signature and returns the signature of an equivalent asynchronous function.
As this example shows, we cannot use the helper type Async<T> with a generic function signature. If we try, we get a non-generic function signature with unknown wherever a generic argument was used.
π» Use Cases
We maintain a plugin system. Plugins are developed against a carefully designed API. For every type in the plugin API, there is a corresponding internal type. Plugin values and internal values are identical at runtime, but their types differ. For instance, the same concept may be represented by a class internally, but by a branded interface towards the plugins.
To convert between an internal type and its corresponding plugin type, we use a recursive mapped type. This words great, unless the value is (or contains) a generic function.
Martin Johns (@MartinJohns)Ryan Cavanaugh (@RyanCavanaugh) I'm not quite sure this is a duplicate. As far as I understand, both #1213 and #44875 propose to introduce new syntax for new kinds of types. This proposal, however, simply suggests that existing syntax should produce more consistent results.
Activity
MartinJohns commentedon Feb 25, 2022
I think you want HKT like #1213 or #44875.
DanielSWolf commentedon Feb 28, 2022
Martin Johns (@MartinJohns) Ryan Cavanaugh (@RyanCavanaugh) I'm not quite sure this is a duplicate. As far as I understand, both #1213 and #44875 propose to introduce new syntax for new kinds of types. This proposal, however, simply suggests that existing syntax should produce more consistent results.
typescript-bot commentedon Mar 2, 2022
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.