如何在不给我错误的情况下进行连接以进行阵列操作。
键入“字符串| IMiddlewareClosure | (string | IMiddlewareClosure)[]'不是数组类型或字符串类型。使用编译器选项'--downlevelIteration'可以迭代迭代器。
尝试了多种创建界面的方法。
private _registerMiddlewares (middleware: string | IMiddlewareClosure | Array<string | IMiddlewareClosure>) {
const oldMiddlewares = this._routes[this._currentRouteIndex].middlewares;
// This spread gives Type 'string | IMiddlewareClosure | (string | IMiddlewareClosure)[]' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
const newMiddleware = [...middleware];
console.log('old: ', oldMiddlewares);
console.log('newest: ', newMiddleware);
}
export interface IMiddlewareClosure {
(): boolean
}
由于它是一个字符串或仅使用这些值创建一个新数组的数组,因此有望工作,但是它给出了Type'string | IMiddlewareClosure | (string | IMiddlewareClosure)[]'不是数组类型或字符串类型。使用编译器选项'--downlevelIteration'可以迭代迭代器。