简体   繁体   中英

What does this typescript scheme mean?

What does this typescript scheme mean?

  interface Validator<T extends FormControl> {
     (c:T): {[error: string]:any};
  }

I'm a bit new to Typescript and I'm trying to understand this interface function. In particular, what does the <T extends FormControl> represent?

And what {[error: string]:any} signify? My guess is the return object of the function is an object with a key of type 'string' and a value of 'any' type. Can someone help clarify?

what does the T extends FormControl represent

This is generics . Basically the <T extends FormControl> introduces a new type T that should be the subtype of FormControl type.

The Validator is a function that takes an object of any type that is a subtype of FormControl , including FormControl type.

what {[error: string]:any} signify?

It specifies a new indexable type with properties of string 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