Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'IArguments' is not an array type

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?

like image 575
jensengar Avatar asked Jun 24 '16 15:06

jensengar


2 Answers

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);
    }
}
like image 162
Reginaldo Camargo Ribeiro Avatar answered Oct 25 '22 10:10

Reginaldo Camargo Ribeiro


this worked for me:

console.log(...Array.from(arguments));
like image 30
Juan Chan Avatar answered Oct 25 '22 10:10

Juan Chan