4 ms·
It can be as loud and purposely unsound as it wants. That won't stop me from thinking it's a bad tool. The problem is that function parameter variance is still
by ragnese 5y ago
It can be as loud and purposely unsound as it wants. That won't stop me from thinking it's a bad tool.
The problem is that function parameter variance is still wrong, even with all the strict flags. You just have to wrap the Dog/Animal in an Array or object. Pass in an { pet: Dog } to a function that accepts a { pet: Animal }, and the function can replace your Dog with a Cat, and TypeScript is perfectly happy to let you call `o.pet.bark()` afterwards.
- Spivak 5y agoLike I get you but I genuinely can not thing of a single time I’ve ever hit this problem organically. I can’t even think of a time I’ve ever even though to modify a parameter when writing JS. I think if the language made every type immutable when passed to a function I wouldn’t even notice. It’s not an excuse because where possible I think TS should be stricter but I don’t think stuff like this really gets in the way of it providing me value when writing code.