简体   繁体   English

Typescript object 阵列类型

[英]Typescript object array type

I have this object,我有这个 object,

 type Data = {
    name: 'string';
    email: 'string,';
  };

  const data:Data[] = [
    { name: 'A',email: 'a@local' },
    { name: 'B', email: 'b@local' },
  ];

I have type as Data and want to have a const of its type but should be array.我的类型为Data并希望拥有其类型的const但应该是数组。 But, am getting error, Type "JSON" is not assignable to type "string"但是,出现错误,类型“JSON”不可分配给类型“字符串”

please help.请帮忙。

const x: "string" can only be the string "string" . const x: "string"只能是字符串"string" const y:string can be any string. const y:string可以是任何字符串。 You need to remove the quotation marks from the type.您需要从类型中删除引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM