首页 > 解决方案 > 传递要在 Typescript 中应用的参数数组

问题描述

解决方案:

private compiledFn: Maybe<(data: any) => void> = null;

我只想使用传递我的参数数组apply

// function... I can see there is a problem here
private compiledFn: Maybe<() => void> = null;

// calling with apply
let arg = [data];
return this.compiledFn.apply(data, arg);

但是得到这个错误:

semantic error TS2345 Argument of type 'any[]' is not assignable to parameter of type '[]'.
Types of property 'length' are incompatible.
Type 'number' is not assignable to type '0'.

标签: typescriptapply

解决方案


推荐阅读