JavaScript函數parseInt
可用於強制給定參數的轉換爲整數使用parseInt函數()時,即參數是否是一個字符串,浮點數,號碼等打字稿:錯誤多項
在JavaScript中,parseInt(1.2)
會產生1
沒有錯誤,但是,在打字稿,它在編譯過程中拋出一個錯誤說:
error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
我失去了一些東西在這裏或者是從打字稿預期的行爲?
是的,這是雅的類型檢查! –
嘗試'parseInt(「」+ 1.2 +「」)' – Mojtaba
'parseInt([2,3])'返回'2'但這並不意味着你應該這樣做... –