You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Distinguishing types between int and double #30543
This proposal introduces new number types int and double or float. Goal is to make a difference between integers and floating point numbers since some JavaScript engines does such kind of difference in the back-end.
Use Cases
As we know about V8 engine, it uses pointer tagging to distinguish between different types such as Smi (small integer), HeapObject, WeakHeapObject etc.
For both o1 and o2 object the engine will create same shapes. See image below:
However, after changing o2.x to some double value, say that o2.x = 5.5; then V8 will use create new subtree from that shape and the old subtree in this shape will be marked as deprecated and will be garbage-collected. Reason for this is because there is a difference how V8 stores Smi and Double values in the memory.
class Point {
constructor(private x: int, private y: int) {}
getX(): int { this.x = x; }
getY(): int { this.y = y; }
}
let point = new Point(12, 5);
point.x = 1.5; // Error: double is not assignable to integer
This proposal does not require a breaking change, since number types are also okay, if one considers some possible performance pitfalls.
Checklist
My suggestion meets these guidelines:
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
Activity
DanielRosenwasser commentedon Mar 22, 2019
Duplicate of #195.
orkhan-huseyn commentedon Sep 14, 2021
If you have red both PRs carefully they have different reasons. I was not proposing it as a syntactic sugar.