I'm trying to compile this TypeScript code in a Bazel ts_library
target:
function distance(
a: [number, number, number],
b: [number, number, number]
): number {
let [x1, y1, z1] = a;
let [x2, y2, z2] = b;
return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2);
}
And I'm getting this error:
error TS2488: Type '[number, number, number]' must have a '[Symbol.iterator]()' method that returns an iterator.
16 let [x1, y1, z1] = a;
~~~~~~~~~~~~
The same function compiles just fine in the TypeScript Playground. There must be something wrong with the Bazel ts_library
setup but I can't figure out what. My tsconfig.json
looks like this:
{
"compilerOptions": {
"target": "ES2015",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Recommended"
}
I'm also getting the same error for a simple number array literal, e.g.:
for (let i of [1, 2, 3]) {
console.log(i);
}
produces this error:
error TS2488: Type 'number[]' must have a '[Symbol.iterator]()' method that returns an iterator.
5 for (let i of [1, 2, 3]) {
~~~~~~~~~
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…