打字稿错误"类型'数字[]'不能指定类型''""

时间:2016-12-08 07:49:36

标签: angular typescript

我在Typescript中遇到以下错误:

  

类型'数字[]'不能分配给' number'

类型的参数

我得到数组的最大值而没有以下错误:

analysis_horizon_array_test: number[] = [];

this.analysis_horizon_array_test.push(1)
console.log(Math.max(this.analysis_horizon_array_test));

如何在不抛出错误的情况下获取数组的最大值?它确实有用。

1 个答案:

答案 0 :(得分:7)

Math.max取个别数字,而不是数组。如果要编译支持的目标,则可以使用扩展语法,否则必须使用apply

console.log(Math.max(...this.analysis_horizon_array_test));
相关问题