[英]Parameter 'info' implicitly has an 'any' type
I have this piece of code:我有这段代码:
const format = winston.format;
format: format.combine(
format.colorize({ level: true, message: false }),
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
)
but when I compile the project I got this error:但是当我编译项目时,我得到了这个错误:
error TS7006: Parameter 'info' implicitly has an 'any' type.
with the solution proposed I got this error:使用提出的解决方案,我得到了这个错误:
src/common/logging/logging.service.ts:95:43 - error TS1005: ',' expected.
95 format.printf(info:any => `${info.timestamp} ${info.level}: ${info.message}`)
This is a Typescript error.这是 Typescript 错误。 It expects you to define a type for the 'info' argument.
它希望您为“信息”参数定义一个类型。 You can replace
info
with info:any
for the fix.您可以将
info
替换为info:any
以进行修复。
Just need a brackets只需要一个括号
format.printf((info:any) => `${info.timestamp} ${info.level}: ${info.message}`)
The problem can be resolved as @BerkOzturk suggested by providing:any type.可以通过提供任何类型来解决@BerkOzturk 建议的问题。 By default the typescript compiler expects that you will provide type for every variable.
默认情况下,typescript 编译器希望您为每个变量提供类型。
The other solution for this issue is to say compiler to stop doing that by setting noImplicitAny to false in tsconfig.json file.这个问题的另一个解决方案是说编译器通过在 tsconfig.json 文件中将 noImplicitAny 设置为 false 来停止这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.