我正在尝试创建自定义记录器。非常简单,但我正在尝试消除错误,因此我没有困惑的输出。我有这样的东西:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log(...arguments);
}
}
但它在控制台中给出了以下错误:
Logger.ts(6,9): Error TS2346: Supplied parameters do not match any signature of call target.
和
Logger.ts(6,24): Error TS2461: Type 'IArguments' is not an array type.
执行此操作的正确方法是什么?
最佳答案
console.log 调用不正确,只是传递接收到的参数:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log(args);
}
}
或者作为一个真正的控制台打印:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log.apply(console, args);
}
}
关于typescript - 类型 'IArguments' 不是数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38016431/