3 ms·
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
by hokkos 11y ago
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-unions http://flowtype.org/docs/dynamic-type-tests.html#tagged-unio...
So I completely abandoned my typing adventure.
- Akkuma 11y agoFlow is being ported to work on windows and there are now builds out there for it https://github.com/OCamlPro/flow https://github.com/OCamlPro/flow & the binary downloads http://www.ocamlpro.com/pub/ocpwin/flow-builds/ http://www.ocamlpro.com/pub/ocpwin/flow-builds/
- hokkos 11y agoThanks, I know but it doesn't work really well with server setup sadly.
- Matthias247 11y agoI 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 === ... }
- hokkos 11y agoThanks, 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.
- Matthias247 11y agoYeah, 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).