7 ms·
Yeah I realise you'd never reach the same level of soundness due to the limitations of the underlying JS (although presumably you could get close with a subset?
by jamesisaac 8y ago
Yeah I realise you'd never reach the same level of soundness due to the limitations of the underlying JS (although presumably you could get close with a subset?). But that's why it's an interesting challenge, and I think what Flow has shown is that it's possible to get a lot closer than had previously been imagined.
If everyone just accepted the argument 4 years ago that "JS will never be sound" then maybe today TS would still just be Java style `interface` annotations for classes. It's not like the Flow team has reached a ceiling at this point... there's still plenty on their roadmap that would continue to improve soundness and expressiveness.
> You can’t have anything approaching ocaml correctness when in typescript all objects with the same shape are interchangeable.
Could you elaborate? Flow has recently switched to exact objects by default[1], which I would have thought would be enough for a sound approach?
[1] https://medium.com/flow-type/on-the-roadmap-exact-objects-by-default-16b72933c5cf https://medium.com/flow-type/on-the-roadmap-exact-objects-by...
- tigershark 8y agoFor example in typescript this is valid: type A = {name: string} type B = {name: string} function print(obj: A) { alert(obj.name);} let a: A = {name: “hello”}; let b: B = {name: “world”} print(a); print(b); 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.
- jamesisaac 8y agoAh 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-with-flows-new-opaque-type-aliases-feature-40e188c2a3f9 https://medium.com/flow-type/hiding-implementation-details-w... [2] https://flow.org/en/docs/types/opaque-types/ https://flow.org/en/docs/types/opaque-types/ [3] https://github.com/Microsoft/TypeScript/issues/15807#issuecomment-301196459 https://github.com/Microsoft/TypeScript/issues/15807#issueco...
- tigershark 8y agoYup that seems to help.
- zeugmasyllepsis 8y agoI'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?