bulletproof-nodejs
bulletproof-nodejs copied to clipboard
getting Property 'error' does not exist on type '{}'
When running npm run build, getting Property 'error' does not exist on type '{}' in src/api/middlewares/attachCurrentUser.ts on Logger. Why?
We need to do JSON.parse(Container.get('logger')) to remove error. It is in many files. Any generic way to solve this problem?
Hi! Let me investigate this and will get back to you
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?
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;
What's the update on this?
Similar to @dzianisreznik's answer:
import { Logger } from 'winston';
const logger: Logger = Container.get('logger');
@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?