[英]Checking JS object types with TypeScript - Cannot find name 'key'
I am very new to TypeScript.我对 TypeScript 很陌生。 I am using it to check types in a JavaScript file with comments.
我用它来检查带有注释的 JavaScript 文件中的类型。
I have an object with values to be arrays of number, and the keys can be any string.我有一个对象,其值为数字数组,键可以是任何字符串。 I declare it like so
我这样声明
/**
* @type { [key: string]: number[] }
*/
let myObj = {};
With this, I get the following error Cannot find name 'key'
.有了这个,我收到以下错误
Cannot find name 'key'
。
What might I be doing wrong here?我在这里可能做错了什么? How should I declare the type?
我应该如何声明类型?
I'm not sure why my original syntax doesn't work, but the following seems to:我不确定为什么我的原始语法不起作用,但以下似乎是:
/**
* @type {Object.<string, number[]}
*/
let myObj = {};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.