简体   繁体   中英

Checking JS object types with TypeScript - Cannot find name 'key'

I am very new to TypeScript. I am using it to check types in a JavaScript file with comments.

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' .

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 = {};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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