接口类型

对象接口

  1. interface IUser {
  2. name: string;
  3. age: number;
  4. sex: "男" | "女";
  5. }
  6. let user: IUser;
  7. user = {
  8. name: "zhangsan",
  9. age: 14,
  10. sex: "男",
  11. };

数组接口

  1. interface IArr {
  2. // 下标类型为 number,值类型为 number | string
  3. [ids: number]: number | string;
  4. }
  5. let ids: IArr = [1, 2, "3", "4"];

函数接口

  1. interface IFun {
  2. (str: string, num: number): void;
  3. }
  4. let fn: IFun = (name: string, age: number) => {
  5. console.log(name + "今年" + age + "岁");
  6. };
  7. fn("张三", 18);

继承