我需要像这样的箭头函数数组
//how can we contain the list of tasks?
private _tasks : ((x: T) => boolean)[];
constructor(...tasks : ((x: T) => boolean)[]) {
this._tasks = tasks;
}
有什么办法可以做到这一点?
我需要像这样的箭头函数数组
//how can we contain the list of tasks?
private _tasks : ((x: T) => boolean)[];
constructor(...tasks : ((x: T) => boolean)[]) {
this._tasks = tasks;
}
有什么办法可以做到这一点?
You have your brackets wrong for inline declarations. Use {
not (
:
class Foo<T>{
private _tasks: { ( x: T ): boolean }[];
constructor( ...tasks: { ( x: T ): boolean }[] ) {
this._tasks = tasks;
}
}
And as steve fenton said I'd use an interface just to remove duplication.
this seems to work for me
private _tasks :Array<(x: T) => boolean>;
您可以使用接口使类型更具可读性:
interface Task<T> {
(x: T) : boolean;
}
function example<T>(...tasks: Task<T>[]) {
}
example(
(str: string) => true,
(str: string) => false
);