1. index type query operators keyof, by keyof we can get all the properties of the composition of the name of a type union type
keyof
Operator, a connection type, a combined type will return all the property names in this type of composition
Info {interface name: String; Age: Number; } the let infoProp: keyof Info; infoProp = "name" ; infoProp = "Age" ; infoProp = "NO"; // error type can not be "" no "", assigned to the "" name "|" age " "
Here keyof Info
is the equivalent"name" | “age”
2. The index access operator is []
, in fact, and we visit a property value of the object is the same syntax
Info {interface name: String; Age: Number; } type NameType = Info [ "name" ]; the let name: NameType = 123; // error type can not be "123" is assigned to the type "string"
NameType = Info type [ "name" ]; get a strinG
123 is the number