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

I would use Typescript, but its type system isn't smart enough to handle the complexity of JS ecosystem. The other day I wanted to move my project to typescript, the first module needed ambient definition that didn't exist in Definitely Typed repo, it was quite annoying to create, and I am not even sure it's correct, then I wanted to type some parsed JSon that had a TYPE_NAME property with a string giving its type, it's basically tagged union and it doesn't exist in Typescript but only in Flow ... but flow doesn't work on Windows. http://flowtype.org/docs/dynamic-type-tests.html#tagged-unio...

So I completely abandoned my typing adventure.



I often use tagged union like interfaces in TS. It's definitly doable, but it might be a little more work than in Flow. For the definitions I do things like interface BaseInterface { TYPE_NAME: string }, interface DervicedInterface extends BaseInterface { ...content }. And to safely access the content of one or the other type I'm using user defined type guards like function isDerived(a: BaseInterface): a is DerivedInterface { return a.TYPE_NAME === ... }


Thanks, I didn't think of that, it's a little more work and error prone with functions and else/if code and less aesthetic than the switch/case that works with Flow, but I might restart my typing goal knowing that.


Yeah, the if/else cascades that you need when there are lots of cases are definitly not on the most elegant side. But maybe some support for type guards in combination with switch/case will follow. In can live with the current situation, because it isn't really better in most other programming languages without sum types (you mostly need some instanceof followed by a type cast).


Flow is being ported to work on windows and there are now builds out there for it https://github.com/OCamlPro/flow & the binary downloads http://www.ocamlpro.com/pub/ocpwin/flow-builds/


Thanks, I know but it doesn't work really well with server setup sadly.




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

Search: