HackerTrans
TopNewTrendsCommentsPastAskShowJobs

TypeScript's number type is a lie(bluepnume.medium.com)

4 points·by bluepnume·2 bulan yang lalu·6 comments
bluepnume.medium.com
TypeScript's number type is a lie

https://bluepnume.medium.com/typescripts-number-type-is-a-lie-6b3b10dd8f54

6 comments

glkindlmann·2 bulan yang lalu
Supporting operator overloading is part of the linked TS issue [1]. But I'm more curious: why did operator overloading in ES6 itself [2] die?

[1] https://github.com/microsoft/TypeScript/issues/42218

[2] https://github.com/tc39/proposal-operator-overloading
bluepnume·2 bulan yang lalu
Probably if nothing else, impossible to have it perform well without static typing?
glkindlmann·2 bulan yang lalu
But traversing the prototype chain (to figure out method dispatch) is also potentially slow without static typing, and we're managing that ok, no?
bluepnume·bulan lalu
True enough. Although personally I prefer to just use regular functions rather than big inheritance chains.
newaccountman2·2 bulan yang lalu
Am I incorrect in thinking this is not a TypeScript problem, but a problem most languages have, and that TypeScript is one of the few with a neat little solution?
bluepnume·2 bulan yang lalu
In most languages you could probably solve this problem with a class. But wrapping all your numbers in a class with runtime consequences, just for a bit of extra type safety, feels quite extreme.