简体   繁体   中英

TypeScript Generics declararation syntax

In the code below what is the meaning of Action = Action?

export type ActionReducerMap<T, V extends Action = Action> = {
  [p in keyof T]: ActionReducer<T[p], V>;
};

It's generic parameter which is constrained to extend Action (ie it can be Action or any subclass of Action ), and its default value, if not supplied, is Action .

Say you declare:

const myReduceMap : ActionReducerMap<SomeType> = ...

omitting the second generic type parameter, here it will default to Action .

V extends Action - this means that V must be a type that extends Action.

= Action -> this means if a type V is not provided then the default will be Action itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM