by Matthias247 · 8y ago · 0 comments
- If I'm dealing with pure data (of varying sources) I use interfaces
- If I'm modelling something which has an identity and state (and probably attached methods to modify the state) I'm using a class.
Wrote a bit more about it here: https://stackoverflow.com/questions/40591413/interface-and-c...
And allows you to use "instanceof". User defined type guards for interfaces are hackish at best.
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.