Typescript “我的论点怎么能成立?”;不匹配任何签名”;控制台的日志?
一个简单的类:Typescript “我的论点怎么能成立?”;不匹配任何签名”;控制台的日志?,typescript,Typescript,一个简单的类: export class Logger { constructor(private name: string) {} debug(...args: any[]) { console.debug(...args) } log(...args: any[]) { console.log(...args) } } 据我所知,我可以将任何内容传递到console.log和console.debug,那么我怎么会得到: src/app/loggin
export class Logger {
constructor(private name: string) {}
debug(...args: any[]) {
console.debug(...args)
}
log(...args: any[]) {
console.log(...args)
}
}
据我所知,我可以将任何内容传递到console.log
和console.debug
,那么我怎么会得到:
src/app/logging.ts(6,5): error TS2346: Supplied parameters do not match any signature of call target.
src/app/logging.ts(10,5): error TS2346: Supplied parameters do not match any signature of call target.
src/app/logging.ts(6,5):错误TS2346:提供的参数与调用目标的任何签名都不匹配。
src/app/logging.ts(10,5):错误TS2346:提供的参数与调用目标的任何签名都不匹配。
执行.apply(args)
是可行的,但是…args
语法的要点是什么
我使用的是TypeScript 2.2.2版。
控制台。log
定义为
log(message?: any, ...optionalParams: any[]): void;
尝试切换到
export class Logger {
constructor(private name: string) {}
debug(msg?: any, ...args: any[]) {
console.debug(msg, ...args)
}
log(msg?: any, ...args: any[]) {
console.log(msg, ...args)
}
}
这是非常有用的,我会试试的。但是出于好奇,您怎么知道
console.log
的定义是什么呢?@Hubro-Typescript附带了标准库的定义。在已安装的typescript中查找目录lib
。在github上,您可以在这里找到它,并且console.log
就在这里