Good point. I've never measured the compiler's performance for using interface vs. type. I see people saying interface inheritance is easier to type-check than type interception, which sounds reasonable.
I think if there's quite a lot of inheritance in the code base, it makes good sense to prefer interfaces that look more object-oriented.
I'll do some more research and maybe update the post later. Thank you!
If I understand github.com/microsoft/TypeScript/wi... correctly, types aren't universally slower, but once you start doing more complex type unions and intersections, it can be faster to use interfaces.
I believe it's mainly due to this statement: "A final noteworthy difference is that when checking against a target intersection type, every constituent is checked before checking against the "effective"/"flattened" type." Though it feels like a limitation of the current tsc implementation, I don't see why checking of type intersection has to be done repeatedly instead of cached.
Would love to see some benchmarks.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Types have a higher performance impact compared to interfaces so in larger codebases prioritizing interfaces over types should be considered.
Good point. I've never measured the compiler's performance for using interface vs. type. I see people saying interface inheritance is easier to type-check than type interception, which sounds reasonable.
I think if there's quite a lot of inheritance in the code base, it makes good sense to prefer interfaces that look more object-oriented.
I'll do some more research and maybe update the post later. Thank you!
Are you sure that's true? I recently heard that that's actually a myth.
If I understand github.com/microsoft/TypeScript/wi... correctly, types aren't universally slower, but once you start doing more complex type unions and intersections, it can be faster to use interfaces.
That's my understanding too.
I believe it's mainly due to this statement: "A final noteworthy difference is that when checking against a target intersection type, every constituent is checked before checking against the "effective"/"flattened" type." Though it feels like a limitation of the current tsc implementation, I don't see why checking of type intersection has to be done repeatedly instead of cached.
Would love to see some benchmarks.