Hacker News new | ask | show | jobs
by Shacklz 1159 days ago
From my point of view, this is one of those cases where structural typing just doesn't work all that well when used for OOP.

Typescript does give you a solution to this problem, namely that you use generics to constrain the parameters of your method:

    let append_animals = <T extends Animal>(animals: T[], animal: T) => animals.push(animal)
Your example now gives the expected error.

TypeScript does indeed have its quirks, but most of them do not really matter for real-life purposes or can easily be worked around like in the example above.