Typescript-常量声明中缺少初始值设定项

Typescript-常量声明中缺少初始值设定项,typescript,syntax,constants,Typescript,Syntax,Constants,我有下面的代码。获取错误SyntaxError:常量声明中缺少初始值设定项 const manufacturers: any[] = []; console.log('Available Products are: '); for (const item of manufacturers) { console.log(item.id); } 如果我将声明更改为constmanufacturers=[] 代码工作正常,但VSCode显示警告 “变量‘manufactur

我有下面的代码。获取错误SyntaxError:常量声明中缺少初始值设定项

const manufacturers: any[] = [];        
console.log('Available Products are: ');
for (const item of manufacturers) {
     console.log(item.id);
}
如果我将声明更改为
constmanufacturers=[]
代码工作正常,但VSCode显示警告
“变量‘manufacturers’在某些无法确定其类型的位置隐式具有类型‘any[]”


我正在使用节点js v12.16.1和typescript:^2.5.3

您需要为
制造商声明一个接口,因为如果您使用
任何
,typescript将无法推断用于类型检查的属性:

interface Manufacturer {
  id: string;
  // add other properties
}

const manufacturers: Manufacturer[] = [];      

无法在2.4.1之前的TypeScript版本上重现此错误。为什么需要声明接口?我需要一个类型为Any的数组。常量制造商:Any[]=[{id=101,name='test 1'},{id=102,name='test 2'}];要么使用接口,要么声明任何接口。我强烈建议使用接口,因为TypeScript需要它来进行类型检查。@RajeshreeNevare嘿,我的回答解决了你的问题吗?是的,声明接口会起作用。但任何接口都不起作用。我已经从tsconfig.json文件中抑制了严格的类型检查。这是一个很好的调用。你应该限制使用由于我的上述观点,任何