Re:Migrate Jest to TypeScript
by tigershark on Wednesday January 16, 2019 @09:52AM
(#18921278)
For example in typescript this is valid:
This is because of typescript structural equality and I think that the same applies to flow given your link.
Obviously if I want a function to accept an email I don’t want the same function to accept an address, but in typescript you can’t guarantee it because you have no way to get rid of structural equality as far as I understood.
[ Parent
| on HN ]
Re:Migrate Jest to TypeScript
by jamesisaac on Wednesday January 16, 2019 @09:59AM
(#18921334)
Ah I see. That can be achieved since Flow 0.51 with opaque types[1][2]. It seems like TypeScript hasn't yet caught up with this functionality[3].
[1] https://medium.com/flow-type/hiding-implementation-details-w...
[2] https://flow.org/en/docs/types/opaque-types/
[3] https://github.com/Microsoft/TypeScript/issues/15807#issueco...
Re:Migrate Jest to TypeScript
by tigershark on Wednesday January 16, 2019 @03:38PM
(#18924898)
Yup that seems to help.
Re:Migrate Jest to TypeScript
by zeugmasyllepsis on Wednesday January 16, 2019 @10:00AM
(#18921344)
I'm certainly not well versed in OCaml, but my understanding is that it is also structurally typed. This particular example would also be permitted in OCaml, correct?
No, records are nominally typed in OCaml, thus the two types `A` and `B` would be deemed incompatible.