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
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.
Proposal
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
Complete Example
related to #12424
The text was updated successfully, but these errors were encountered: