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

You can encode that "correctly" in pure JS

   class LoadingState extends State {}
   class ResultState extends State {}
   class ErrorState extends State {}
   const state: State = new LoadingState
Generally it's a bad pattern to have dependant fields like your example, but you don't need TS to solve it.




Of course you can do it in JS too.

But you can't reason on the different cases aided by the type checker.

Also, using classes or POJOs is merely an implementation detail.


Thats OOP, we don't do that anymore!!! /s



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

Search: