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

Importing Kernel interface is difficult #298

Closed
Jameskmonger opened this issue Jul 24, 2016 · 6 comments
Closed

Importing Kernel interface is difficult #298

Jameskmonger opened this issue Jul 24, 2016 · 6 comments

Comments

@Jameskmonger
Copy link
Member

Expected Behavior

It should be easier to import the Kernel interface. I expected to be able to do:

import { IKernel } from 'inversify';

Current Behavior

I have to import the interface like so:

import * as Inversify from 'inversify';

// the Kernel interface is then reachable here: Inversify.interfaces.Kernel;

Context

I want to be able to reference the Kernel interface as a function argument.

@remojansen
Copy link
Member

We moved the interfaces under the interfaces namespace because we decided to remove the I prefix from all interfaces:

import { Kernel } from "inversify"; // is Kernel the class or the interface?

By doing the following we can solve the naming collision:

import { interfaces, Kernel } from "inversify"; // is Kernel the class or the interface?
let kernel: interfaces.Kernel = new Kernel();

@remojansen
Copy link
Member

Hi @Jameskmonger can this be closed? Do you have any ideas about how to improve this without introducing I prefix?

@remojansen remojansen added this to the 2.x milestone Jul 27, 2016
@Jameskmonger
Copy link
Member Author

I personally think that we should add the I prefix to all interfaces.

The documentation that @mocanu-razvan linked to in #242 was for writing declaration files rather than writing TypeScript.

I don't know of any other projects where the interfaces are stored in a separate interfaces module.

I would expect to be able to import them like this (and I think lots of others would also):

import { Kernel, IKernel } from 'inversify';

@remojansen
Copy link
Member

I also like the I prefix but it is not recommended in TypeScript. I researched multiple issues and all the developers seems to agree:

And it has recently been added as a TsLint rule. I understand that:

import { Kernel, IKernel } from 'inversify';
let kernel: IKernel = new Kernel();

Is nice but is breaking the recommended style guides.

The current solution:

import { Kernel, interfaces } from 'inversify';
let kernel: interfaces.Kernel = new Kernel();

Requires just one extra word and it allow us to follow the style guide.

@Jameskmonger
Copy link
Member Author

I am happy with the style, I guess it is just odd coming from a .NET perspective. Will close this as not an issue :)

@remojansen
Copy link
Member

Thanks!

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

No branches or pull requests

2 participants