提问人:MHC 提问时间:8/19/2023 更新时间:8/19/2023 访问量:24
在 VSCode 中编译打字稿时出错
Error while compiling typescript in VSCode
问:
我有以下代码正在尝试编译:
function twoSum(nums: number[], target: number): number[] {
let res:number[] = [];
let dict = new Map<number, number>();
for (let [index, value] of nums.entries()) {
if (dict.has(target - value)) {
let current = dict.get(target - value)!;
res.push(current);
res.push(index);
break;
}
dict.set(value, index);
}
return res;
};
但是我收到以下错误:
test.ts:4:32 - error TS2802: Type 'IterableIterator<[number, number]>' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
4 for (let [index, value] of nums.entries()) {
我正在使用 tsc 进行编译。我已经更新了这样的tsconfig.json:
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
"include": [ "test.ts", "src/**/*" ],
"downlevelIteration": true,
"target": "es2023",
"lib": ["es2023"],
有人可以帮忙吗?
只想编译和运行代码。我正在使用 VSCode 学习打字稿。
答: 暂无答案
评论