2 ms·
> That, and nominal typing can be really convenient (coming to TS soon, hopefully). I think you meant structural typing? TS was always nominally typed. I searc
by klibertp 9y ago
> That, and nominal typing can be really convenient (coming to TS soon, hopefully).
I think you meant structural typing? TS was always nominally typed. I searched for a bit and it looks like TS also supports structural typing with explicit interfaces, and I think Flow tries to infer such types? I don't use either one, so I'm not sure about the details.
- cowmoo728 9y agoTS is structurally typed. You declare the fields you expect on a type or interface, and as long as an object has at least those fields, it will typecheck. Nominal typing would mean that you could declare type A and type B with identical fields, but if something is declared as A, it cannot be used in place of B. TS has a strange workaround to get nominal typing for now: https://basarat.gitbooks.io/typescript/docs/tips/nominalTyping.html https://basarat.gitbooks.io/typescript/docs/tips/nominalTypi...
- klibertp 9y agoThat's interesting - I'm almost sure last time I checked (possibly a couple years back) TS used nominal typing. Do you know if this changed at some point, or is it just my memory being bad?
- RyanCavanaugh 9y agoTypeScript has used structural typing since the beginning. Classes used to be nominal, but changed to structural (except for classes with private fields) at some point.
- klibertp 9y ago> Classes used to be nominal, but changed to structural Ah, ok, makes sense. I think I was last looking at TS around version 1.1 or something like that. Thanks!