A
A
Alexey Sundukov2019-05-24 14:04:36
JavaScript
Alexey Sundukov, 2019-05-24 14:04:36

How to make the IDE understand the contents of the DI container?

I am using the Awilix library to create a DI container. The content of the DI.ts file is:

import * as _ from 'lodash';
import {ModuleDescriptor} from "awilix";

const awilix = require('awilix');
const container = awilix.createContainer();

// Загружаем в контейнер сервисы (службы) реализующие бизнес логику
container.loadModules([
    [
        __dirname + '/../services/*.ts',
        {
            register: awilix.asClass,
            lifetime: awilix.Lifetime.SINGLETON,
        }
    ]
], {
    formatName: (name:string, descriptor:ModuleDescriptor) => {
        return _.lowerFirst(name) + 'Service';
    },
    resolverOptions: {
        lifetime: awilix.Lifetime.SINGLETON,
        register: awilix.asClass,
    }
});

export default container.cradle;

I use like this:
import Statement from "../services/Statement";
import DI from "../System/DI";
/** @type Statement */
let service = DI.statementService;

and it works fine, but it is extremely inconvenient that the IDE (I have PHPStorm) does not understand that there is a statementService property inside DI and this is a Statement object. I'm trying to do it through JSDocs, but it doesn't work. Is there any way to suggest this to him?
UPD: I realized that type for let works if you do export default container.cradle in DI.ts. But want more. It would be desirable to register it in DI.ts and that the IDE would understand it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question