I'm trying to create a custom logger. Pretty simple but I'm trying to get rid of the errors so I don't have muddy output. I have something like this:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log(...arguments);
}
}
but it gives the following errors in the console:
Logger.ts(6,9): Error TS2346: Supplied parameters do not match any signature of call target.
and
Logger.ts(6,24): Error TS2461: Type 'IArguments' is not an array type.
What is the proper way to do this?
The console.log call is incorrect just pass ahead the paramater received:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log(args);
}
}
Or to print as a real console:
@Injectable()
export class Logger {
log(...args: any[]) {
console.log.apply(console, args);
}
}
this worked for me:
console.log(...Array.from(arguments));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With