DEV Community

Discussion on: How To Use A TypeScript Interface?

Collapse
 
mbarzda profile image
Martynas Barzda

As long time developer with TypeScript, I would suggest:

  1. Interfaces do not need "I" prefix in TypeScript, because there is implements clause, which means that you are using an interface. This pattern is obsolete and pollutes codebase;
  2. If you want make your object stricter, use type instead interface. That's why TypeScript is for. Let's leave interface just for classes. If your app is not written in OOP, none of interfaces should be in your codebase.
Collapse
 
devbyrayray profile image
Dev By RayRay

@mbarzda thanks for the extra details 🙏.

Many codebases I've worked with use the I as a prefix. But I agree with your reason why it's not a smart idea 💡.

And as you said, let's leave the interface for a class, makes perfect sense. So that's making it much more clear when to use a interface or a type.