Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 1.39 KB

File metadata and controls

51 lines (32 loc) · 1.39 KB

Interface

interface vs type alias

You should prefer type alias over interface.

Why?

Interface syntax is carried over from other Object Oriented languages such as Java and C#.

The difference between type and interface is become very small. type can do most of interface can do except merging definitions.

On the other hand, type can do quite a lot more compare to interface, and the syntax is more concise and straight forward.

Why not?

While type is more expressive and generally more powerful, interface is more performant.

So if your type is simple, you can use interface instead.

Reference

Naming

  • Name interface in PascalCase.
  • Do not prefix interface with I.
// bad
interface myInterface { }
interface IDisposable { }

// good
interface MyInterface { }
interface Disposable { }

Why?

The concept of an interface in TypeScript is much more broad than in C# or Java, the IFoo naming convention is not broadly useful.

Microsoft Coding Guideline

Why?