3 ms·
> And, while I agree that mutating an input param is generally a bad idea, that's no excuse for the type system to not be correct. Yes there is: it's more usef
by phailhaus 5y ago
> And, while I agree that mutating an input param is generally a bad idea, that's no excuse for the type system to not be correct.
Yes there is: it's more useful. I don't want to have to write a version of my function for every possible subtype. If I'm not mutating properties, then it's more useful for objects and lists to be covariant. It's not "incorrect" for the type system to do so, that is a deliberate design choice that makes functional patterns easier to express.
This is part of what makes TypeScript so great: they made careful tradeoffs given that they were working off of an existing language. JavaScript doesn't really have immutable objects or lists, but invariance would have caused far more problems than it would have solved.