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
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.
The text was updated successfully, but these errors were encountered:
@MartinJohns@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.
Suggestion
π Search Terms
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
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.Now let's give it a generic 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 withunknown
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.
The text was updated successfully, but these errors were encountered: