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
[Suggestion] Mapped types with inner generic arguments and constraints #17375
I'd like to suggest a feature where in mapped types we could unwrap some of the properties. I'm trying to solve a problem where I want to unpromise a type, and this requires access to the inner generic argument type. This is useful in creating redux style reducers that are strongly typed.
Example
//i'd like access to the inner generic arguments, without having to pass TPayloadtypeUnpromise<TPayload,TPromiseextendPromise<TPayload>>=TPayload;//and then use that also as a type guard for mapped typestypeReducer<TActions>={[KinkeyofTActionswhereTActions[K]extendsPromise<any>]: (payload: Unpromise<TActions[K]>)=>void;[KinkeyofTActionswhereTActions[K]!extendsPromise<any>]: (payload: TActions[K])=>void;}
Complete Example
//redux style actions classclassActions{get(): Promise<string>;}//redux style reducerclassMyReducer{get(payload:string){...}}//unpromise typetypeUnpromise<TPayload,TPromiseextendPromise<TPayload>>=TPayload;//example derived usage with generic constraintstypeReducer<TActions>={[KinkeyofTActionswhereTActions[K]extendsPromise<any>]: (payload: Unpromise<TActions[K]>)=>void;[KinkeyofTActionswhereTActions[K]!extendsPromise<any>]: (payload: TActions[K])=>void;}//redux style reducer wireupfunctionhandleActions<TActions>(actions: TActions,reducer: Reducer<TActions>){
...
}//this would check that MyReducer has methods similar to Actions taking in the resolved promise payload as an argumenthandleActions(newActions(),newMyReducer());
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
mhegazy commentedon Aug 26, 2017
See #12424 and #17077
mhegazy commentedon Sep 11, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.