Search code examples
reactjstypescriptobject-type

Typescript object array type


I have this 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. But, am getting error, Type "JSON" is not assignable to type "string"

please help.


Solution

  • const x: "string" can only be the string "string". const y:string can be any string. You need to remove the quotation marks from the type.