by ljm · 2y ago · 0 comments
type A = { a: string; b: string }
type B = { a: string; b: string; c: string }
If you created a new object like this: { a: “foo”, b: “bar”, c: “baz” }
It would satisfy both type A and type B.That won’t work quite so easily in go without messing around a bit.
So far it hasn't bitten me in the behind, but I wouldn't advise anyone to use that logic for production code.
The difference between structural typing and duck typing is that one is evaluated at compile time, while the other at runtime. Typescript is erased before runtime, so it by itself does not exhibit duck typing features, although Javascript does.