我想知道为什么打字稿,出现以下错误抱怨压缩功能:打字稿误差与Lodash
(22,28): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number[]'.
当我使用zip函数使用以下参数:
let ranges = ["0-100", "100-200", "200-300", "300-400", "400-500"];
let arrays = [[19.99, 49.99, 49.99, 49.99, 29.99, 29.99, 9.99, 29.99, 34.99, 34.99, 59.99], [149.99, 179.99, 129.99, 149.99, 129.99, 199.99, 129.99], [209.99, 249.99, 292.99, 279.99, 219.99]];
let result = _.zip(ranges, arrays);
但是,如果我使用_.zipObject,错误消失。
如果重要,我使用typings install lodash --save
安装类型信息。
更新2
我觉得zip
不喜欢与不同类型的接收参数。在这种情况下,ranges
是类型string[]
和arrays
类型number[]
。
UPDATE
我错了。我改变了价值观的arrays
使用字符串,但现在我得到这个略有不同的错误:
(24,28): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'string[]'.
也许有在变量arrays
有关嵌套数组的东西吗?
那么显式指定联合类型为泛型参数呢? '_.zip <数字|字符串>(...)' –
谢谢。让我尝试。 –
不,仍然无法正常工作。我想你的意思是明确输入'_.zip'的预期输出。我认为这将是一个数组的数组。 –