Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS error Logger.error #45

Open
hubochkin opened this issue Nov 11, 2019 · 7 comments
Open

TS error Logger.error #45

hubochkin opened this issue Nov 11, 2019 · 7 comments

Comments

@hubochkin
Copy link

hubochkin commented Nov 11, 2019

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 ?

@santiq
Copy link
Owner

santiq commented Nov 11, 2019

  • Are you registering the logger within typedi?
  • Are you calling the event subscriber loader before the container's initialization?

@hubochkin
Copy link
Author

hubochkin commented Nov 12, 2019

@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?

@peiris
Copy link

peiris commented Nov 26, 2019

@santiq I'm having the same issue here. @hubochkin Were you able to fix this issue?

@hubochkin
Copy link
Author

@peiris No, I didn't :(

@mattlehrer
Copy link

mattlehrer commented Dec 10, 2019

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.

@bjfletcher
Copy link

bjfletcher commented Dec 21, 2019

This looks to me to be a duplicate of #27

@lechodiman
Copy link

I got this to work by specifying the generic type as winston.Logger

const logger = Container.get<winston.Logger>('logger');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants