-
Notifications
You must be signed in to change notification settings - Fork 721
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
Suggestion to remove I
prefix from interface names
#242
Comments
Coming from C# I have a habit of using IFoo for interfaces. Regardless of what the guys at Typescript recommend; an interface in Typescript has a different purpose than a class. Typescript interfaces are for compile time anyways, they do not exist in the compiled javascript. So, having a naming convention that allows developers to visually identify an interface from a class makes a lot of sense to me. And I think as far as the compiler goes it could care less if you use an interface vs a class to define a type reference, you could subject yourself to alot of run time errors if you use an interface in place of a class because of a simple mixup. To take the argument a bit further, most anyone can argue that conventions are not needed, the software can still compile and run without them. But the benefits of conventions contribute to quality and productivity. In C# and Java the compiler does not care if you prefix your interfaces with an I, but it's a widely used convention thats been around for years and has more to do with identifying the purpose of the file/code than how it's used in compilation and run time. In Typescript an interface defines a contract, like for a json response from the server or an Api from a third party library and it has no implementation. Sounds alot like interfaces in other platforms so why not prefix it with an I? |
I also come from a Java and C# background and I believe that using I like InversifyJS to be driven by the community not by myself so I have created a survey that you will be able to find here. I will leave this issue open for some time and see what our users think... |
One idea that I came across supporting the view that For example, one should not define an Another view is that prefixing interfaces with |
I think the I prefixed interface still does have a place, I also come from Java/C# and have used many other languages. My argument is that sometime an interface is just that, an Interface, not a generic identifier. I use abstract classes for alot of things, so I also use an A prefix at times, so it makes it easier in my mind to be able to identify an interface vs. abstract vs. concrete class. There have been many conventions, but the strongest convention has also always been, be consistent, so if we are going to break convention, always break that convention. |
I've been doing some reading online and everyone in the TypeScript team seems very sure about the idea of not using I was thinking about this over the weekend and really is not a big dial because you can still develop your application using the This will be merged as soon as I get the new inversify.d.ts ready and released as |
👍 - Totally support not using |
Expected Behavior
The TypeScript guidelines found on their website's page on Writing Declaration Files say:
What do you think about adopting this advice?
Current Behavior
There are a lot of interfaces I can see in the library that have their names prefixed with
I
, e.g.IKernel
,IProvider
etc.Possible Solution
Remove the
I
prefix from all interface names.Context
I am starting out with this library and TypeScript almost at the same time.
Your Environment
The text was updated successfully, but these errors were encountered: