Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
654 views
in Technique[技术] by (71.8m points)

Plain TypeScript tuple missing '[Symbol.iterator]()' method in bazel ts_library

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]) {
                ~~~~~~~~~

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...