索引签名
  1. interface StringArray{
  2. [index:number]:string
  3. }
  1. interface NumberDictionary{
  2. [index:string]:number
  3. length:number
  4. //name:string 报错 它和[index:string]重合了, 但是类型却不一致
  5. //[index:string]:number|string //使用联合类型解决
  6. }
  7. const person:NumberDictionary = {
  8. length:1,
  9. qqb:111,
  10. 21:123
  11. }

索引签名 不管是 数字类型还是string 它们是一样,也就是当你使用了string的索引签名后 不再被允许使用number类型

继承
  1. interface BasicAddress{
  2. name?:string
  3. street:string
  4. }
  5. interface AddressWithUnit extends BasicAddress{
  6. unit:string
  7. }
  8. interface Colorful {
  9. color: string;
  10. }
  11. interface Circle {
  12. radius: number;
  13. }
  14. interface ColorfulCircle extends Colorful, Circle {}
交叉类型
  1. interface Colorful {
  2. color: string;
  3. }
  4. interface Circle {
  5. radius: number;
  6. }
  7. type ColorfulCircle = Colorful & Circle;
  8. function draw(circle: Colorful & Circle) {
  9. console.log(`Color was ${circle.color}`);
  10. console.log(`Radius was ${circle.radius}`);
  11. }