by jjnoakes · 3y ago · 0 comments
https://www.typescriptlang.org/play?#code/MYewdgziA2CmB00QHM...
parseInt("10", 0) => 10
parseInt("10", 1) => NaN
parseInt("10", 2) => 2
This doesn't seem particularly surprising to me?[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
parseInt("10", 0, ["10", "10", "10"])
parseInt("10", 1, ["10", "10", "10"])
parseInt("10", 2, ["10", "10", "10"])
https://www.typescriptlang.org/play?#code/ATAOEMCcGcFMEkB2AX...So TypeScript intentionally suppresses this kind of complaint when matching up function types even though it issues them when calling functions directly. The reason for that has a justification, but in contexts like this, I think it is a WAT-worthy interaction.
https://github.com/microsoft/TypeScript/wiki/FAQ#why-are-fun...
I understand why it is this way, but I think it is very surprising and unintuitive behavior.