TS2344 & TS2339 errors on building with v8.17
Closed this issue ยท 9 comments
Type '{ customLevels: { log: number; }; }' does not satisfy the constraint 'string'. Property 'log' does not exist on type 'Logger<{ customLevels: { log: number; }; }>'.
Works fine with Pino 8.15.0.
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
this is also trigger error on our pipeline. the easiest fix is define the types
from:
export function createLogger(module: string, config?: Bindings): Logger { return log.child({ module, ...config }); }
to:
export function createLogger(module: string, config?: Bindings): Logger<string> { return log.child({ module, ...config }); }
cc @kibertoad
I am happy to look into it, but definitely need a reproduction.
@mcollina sorry for not adjusting code to reproduce. So here it is. Simply create logger class inside your TS project like here:
export class Logger {
private static _instance: Logger;
logger: PinoLogger<{ customLevels: { log: number } }>;
constructor() {
if (!Logger._instance) {
Logger._instance = this;
this.logger = pino({
customLevels: {
log: 5,
},
level: 'log',
transport: {
target: 'pino-pretty',
options: {
colorize: true,
},
},
});
}
return Logger._instance;
}
log(msg: string, obj?: object) {
obj ? this.logger.log(obj, msg) : this.logger.log(msg);
}
}
And then just create a new logger instance.
Thank you, guys, for your quick response!
This should work:
export class Logger {
private static _instance: Logger;
logger: PinoLogger<'log'>;
constructor() {
if (!Logger._instance) {
Logger._instance = this;
this.logger = pino({
customLevels: {
log: 5,
},
level: 'log',
transport: {
target: 'pino-pretty',
options: {
colorize: true,
},
},
});
}
return Logger._instance;
}
log(msg: string, obj?: object) {
obj ? this.logger.log(obj, msg) : this.logger.log(msg);
}
}
@mcollina this works fine!
Didn't saw the changes in 'PinoLogger' generic type, because used previous version on local mechine.
Many thanks for help! <3
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.