bulletproof-nodejs
bulletproof-nodejs copied to clipboard
TS error Logger.error
src/subscribers/user.ts:29:14 - error TS2339: Property 'error' does not exist on type 'unknown'
import { Container } from 'typedi';
const Logger = Container.get('logger');
Logger.error(`🔥 Error on event ${events.user.signIn}: %o`, e);
But if I do the next code - everything is fine
import Logger from '../loaders/logger';
Logger.error(`🔥 Error on event ${events.user.signIn}: %o`, e);
As I can see. typedi do not see levels in Container. How can I fix this ?
- Are you registering the
logger
within typedi? - Are you calling the event subscriber loader before the container's initialization?
@santiq Container.set('logger', LoggerInstance) in dependencyInjector
But it just a copy of this git project. I cant build a project.
Can we fix this together?
@santiq I'm having the same issue here. @hubochkin Were you able to fix this issue?
@peiris No, I didn't :(
I got this to work by adding a LoggerInterface in src/interfaces/LoggerInterface.ts:
interface LoggerInterface {
debug(message: string, ...args: any[]): void;
info(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
error(message: string, ...args: any[]): void;
silly(message: string, ...args: any[]): void;
}
and then adding that type to every definition of the logger container:
const logger: LoggerInterface = Container.get('logger');
I am extremely new to TS so there is probably a better way to do this but it does appear to work.
This looks to me to be a duplicate of https://github.com/santiq/bulletproof-nodejs/issues/27
I got this to work by specifying the generic type as winston.Logger
const logger = Container.get<winston.Logger>('logger');