简体   繁体   中英

Typescript interface generics

Could someone help me understand what T = {} means in the following typescript interface? I cannot find docs indicating such usage. How is it different from just T ?

interface CustomProps<T = {}> {
      itemId: string;
      id: string;
}

They're called generic parameter defaults and were introduced in TypeScript 2.3. You can find the documentation here .

For your example, it means that if no type parameter is specified, it will default to {} , which is commonly referred to as the empty object type .

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