News for hackers. Stuff that matters.
Re:TypeScript’s quirks: How inconsistencies make the languag... by DonHopkins on Saturday February 01, 2020 @07:07AM (#22210081)
CatDog typing sure looks, walks, and quacks a lot like Duck typing.

https://en.wikipedia.org/wiki/CatDog

https://en.wikipedia.org/wiki/Duck_typing

Re:TypeScript’s quirks: How inconsistencies make the languag... by redmorphium on Saturday February 01, 2020 @07:29AM (#22210165)
From your second link:

https://en.wikipedia.org/wiki/Duck_typing#Structural_type_sy...

> Duck typing is similar to, but distinct from structural typing. Structural typing is a static typing system that determines type compatibility and equivalence by a type's structure, whereas duck typing is dynamic and determines type compatibility by only that part of a type's structure that is accessed during run time.

Re:TypeScript’s quirks: How inconsistencies make the languag... by kazinator on Tuesday February 04, 2020 @12:21AM (#22232662)
That looks like ooks like "original research". It's obvious that what is described as dynamic-only duck typing could be statically checked. So that is to say, a given expression foo.bar in the program could be statically checked to make sure that all possible values that foo takes on have property bar. If three classes A, B, C in the program have property foo, then this means verifying that foo is A | B | C. Thus, "static duck typing".
Re:TypeScript’s quirks: How inconsistencies make the languag... by greenshackle2 on Saturday February 01, 2020 @12:25PM (#22211689)
Kind of but not really. If you ask a "duck" to quack, duck typing is satisfied with any object that implements the quack method.

With structural typing, the type system will check that the "duck" not only quacks but also looks like and walks like a duck, before it is allowed to be asked to quack.

EDIT: of course with small enough interfaces you can get structural typing pretty close to duck typing, if you have interfaces "QuacksLikeDuck", "WalksLikeDuck", "LooksLikeDuck", etc. instead of one big "Duck" interface.