Giter VIP home page Giter VIP logo

Comments (7)

dzianisreznik avatar dzianisreznik commented on May 22, 2024 3

When you get a service from DI container you should define the returned value as Logger interface from winston.

import winston from 'winston';

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

from bulletproof-nodejs.

bjfletcher avatar bjfletcher commented on May 22, 2024 1

Similar to @dzianisreznik's answer:

import { Logger } from 'winston';

const logger: Logger = Container.get('logger');

from bulletproof-nodejs.

lakshitaverma avatar lakshitaverma commented on May 22, 2024

We need to do JSON.parse(Container.get('logger')) to remove error. It is in many files. Any generic way to solve this problem?

from bulletproof-nodejs.

santiq avatar santiq commented on May 22, 2024

Hi!
Let me investigate this and will get back to you

from bulletproof-nodejs.

lakshitaverma avatar lakshitaverma commented on May 22, 2024

Instead of directly importing this - import { Container } from 'typedi'; we can create a wrapper over this and that wrapper will return us the parsed version of object. What do you say?

from bulletproof-nodejs.

peiris avatar peiris commented on May 22, 2024

What's the update on this?

from bulletproof-nodejs.

SamsadSajid avatar SamsadSajid commented on May 22, 2024

@dzianisreznik and @bjfletcher this approach solves the problem.

Though without importing Logger, I used @ts-ignore like the following and it also resolved the problem though it was not neat and I don't like it.

const logger = Container.get("logger");
// @ts-ignore
logger.info("Breaking Log");

Now with your solutions, I was wondering if I'm getting the instance from Container then are we using
import { Logger } from 'winston';

just to tell typescript that the instance we are pulling out from the DI container is of type Logger?

And does not import { Logger } from 'winston'; this line also import Logger codes from winston? Does not this increase the file size when transpiling?

from bulletproof-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.