Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree. Using classes for entities allows you to use libraries such as https://github.com/typestack/class-transformer

And allows you to use "instanceof". User defined type guards for interfaces are hackish at best.



"instaceof" is something I would advise against for any code that might be called from another module.

If you have different modules requiring that same module and they for whatever reason (webpack behavior, node not deduping properly, npm link, different versions, etc), that instanceof will fail and the caller will be left scratching their head as to why their object fails the check.

In JavaScript (and by extension TypeScript), you are best left to duck-typing for run-time checks.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: