jen*_*gar 4 typescript angular
我正在尝试创建自定义记录器。很简单,但是我试图摆脱错误,所以我没有泥泞的输出。我有这样的事情:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log(...arguments);
}
}
Run Code Online (Sandbox Code Playgroud)
但它在控制台中出现以下错误:
Logger.ts(6,9): Error TS2346: Supplied parameters do not match any signature of call target.
Run Code Online (Sandbox Code Playgroud)
和
Logger.ts(6,24): Error TS2461: Type 'IArguments' is not an array type.
Run Code Online (Sandbox Code Playgroud)
正确的方法是什么?
console.log调用不正确,只是将收到的参数传递给了:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log(args);
}
}
Run Code Online (Sandbox Code Playgroud)
或打印为真实的控制台:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log.apply(console, args);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2943 次 |
| 最近记录: |