自学内容网 自学内容网

Typescript再学习-对象类型(3)

// 对象必须给正确的属性和类型

let person: {

  name: string;

  age: number;

  sex: string;

};

person = {

  name: "张三",

  age: 18,

  sex: "男",

};

let person2: {

  name: string;

  age: number;

  sex: string;

};

person2 = {

  name: "张三",

  age: 18,

  sex: "男",

  // 对象字面量只能指定已知属性,并且“height”不在类型“{ name: string; age: number; sex: string; }”

  height: 170,

};

// 对象必须给正确的属性和类型
let person: {
  name: string;
  age: number;
  sex: string;
};
person = {
  name: "张三",
  age: 18,
  sex: "男",
};
let person2: {
  name: string;
  age: number;
  sex: string;
};
person2 = {
  name: "张三",
  age: 18,
  sex: "男",
  // 对象字面量只能指定已知属性,并且“height”不在类型“{ name: string; age: number; sex: string; }”
  height: 170,
};


原文地址:https://blog.csdn.net/xvzhengyang/article/details/136934596

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!