如果有問題,我正在使用Typescript〜2.4。在類型陣列上使用forEach時遇到問題
我有一個變量,被鑄造爲{} | {}[] | string[]
。我做了一個檢查,當它是一個數組,並且想要迭代它時。我想通forEach
是最好的對:
(<{}[] | string[]>data).forEach((val) => {
this.options.push(setupValue(val));
});
但它說Cannot invoke an expression whose type lacks a call signature.
我不能看到我錯在哪裏。我不知道這是如何使用Typescript或我自己的邏輯的問題?
有趣的是,'(<{}[]>數據).forEach'和'(數據).forEach'的罰款。 –
cartant
或許這是Typescript的錯誤?或者似乎是有意的行爲? – RhoVisions
對我來說看起來越野車,但其他人可能更多地瞭解具體情況。 – cartant