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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting Property 'error' does not exist on type '{}' #27

Open
lakshitaverma opened this issue Aug 4, 2019 · 7 comments
Open

getting Property 'error' does not exist on type '{}' #27

lakshitaverma opened this issue Aug 4, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@lakshitaverma
Copy link
Contributor

lakshitaverma commented Aug 4, 2019

When running npm run build, getting Property 'error' does not exist on type '{}' in src/api/middlewares/attachCurrentUser.ts on Logger. Why?

@lakshitaverma lakshitaverma changed the title When running npm run build, getting Property 'error' does not exist on type '{}' in src/api/middlewares/attachCurrentUser.ts getting Property 'error' does not exist on type '{}' Aug 4, 2019
@lakshitaverma
Copy link
Contributor Author

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

@santiq
Copy link
Owner

santiq commented Aug 4, 2019

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

@santiq santiq added the bug Something isn't working label Aug 4, 2019
@lakshitaverma
Copy link
Contributor Author

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?

@dzianisreznik
Copy link

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;

@peiris
Copy link

peiris commented Nov 26, 2019

What's the update on this?

@bjfletcher
Copy link

Similar to @dzianisreznik's answer:

import { Logger } from 'winston';

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

@SamsadSajid
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants