简体   繁体   English

参数 'info' 隐式具有 'any' 类型

[英]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.

相关问题 参数 'req' 隐含地具有 'any' 类型 - Typescript - Parameter 'req' implicitly has an 'any' type - Typescript RN打字稿中参数隐式具有任何类型 - Parameter implicitly has any type in RN typescript TypeScript - 元素隐式具有“任何”类型 [...] 在类型上未找到具有“字符串”类型参数的索引签名 - TypeScript - Element implicitly has an 'any' type [...] No index signature with a parameter of type 'string' was found on type 'req' 已声明,但它的值从不。 参数“req”隐式具有“任何”类型 - 'req' is declared but its value is never . Parameter 'req' implicitly has an 'any' type Node + TypeScript:“this”隐式具有类型“any” - Node + TypeScript: 'this' implicitly has type 'any' Typescript/nodejs:变量在某些位置隐含类型为“any” - Typescript/nodejs: variable implicitly has type 'any' in some locations 获取本地 JSON 数据:该元素隐式具有类型“any” - Get local JSON data: The element has a type "any" implicitly 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型“{}” - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{} TypeScript警告=> TS7017:对象类型的索引签名隐式具有任何类型 - TypeScript warning => TS7017: Index signature of object type implicitly has any type 'this' 隐含类型为 'any' 因为它没有类型 annotation.ts(2683) - 'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM