Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Numeric Literals #24828

Closed
MaxGraey opened this issue Jun 9, 2018 · 7 comments
Closed

Extended Numeric Literals #24828

MaxGraey opened this issue Jun 9, 2018 · 7 comments
Labels
ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript Waiting for TC39 Unactionable until TC39 reaches some conclusion

Comments

@MaxGraey
Copy link

MaxGraey commented Jun 9, 2018

Search Terms

  • extended-numeric-literals
  • extended numeric literals

Suggestion

Support tc39/proposal-extended-numeric-literals (Stage 1)

Use Cases

For represent lengths in pixels, inches, degrees, radians, seconds and other units without calling specifically conversion methods in runtime (if this possible).

const time = 100s // transforms to `100,000` ms
const angle = 180° // transforms to `3.1415926536` radians

Examples

function deg(value: number): number {
   return value * (Math.PI / 180);
}

function °(value: number): number {
   return deg(value);
}

function _f32(value: number): number {
  return Math.fround(value);
}

function _u32(value: number): number {
  return value >>> 0;
}

function px(value: number): string {
  return `${ value }px`;
}

var angle = 30deg; // transforms to `0.5235987756`
const angle2 = 180°; // transforms to `pi` (`3.1415926536`)
let count = 1_000_000_u32;
var float32 = 1.0_f32;
canvas.style.width = 512px; // transforms to "512px" string

Also related to #15096

@Shinigami92
Copy link

I think that would be a great feature, but also that it could cause confusion for newbies who would read code from teammates

@DanielRosenwasser DanielRosenwasser added Suggestion An idea for TypeScript ES Next New featurers for ECMAScript (a.k.a. ESNext) labels Jun 9, 2018
@Kingwl
Copy link
Contributor

Kingwl commented Jun 10, 2018

I don't think this will reach stage-3 in the near future (1-3 years)
and it is ugliness

@MaxGraey
Copy link
Author

MaxGraey commented Jun 10, 2018

This is already used with the arrival of BigInt. And with success has taken hold in such modern languages ​​like Rust, Ruby, Swift

@Shinigami92
Copy link

@MaxGraey So I think that this feature is related to Javascript, not Typescript

@MaxGraey
Copy link
Author

MaxGraey commented Jun 10, 2018

If this will land in JavaScript it should support by Typescript as well, isn't it? String templating with tags has been pretty useful feature. Extended numeric literals just like templating but for numbers

@Shinigami92
Copy link

If this will land in JavaScript it should support by Typescript as well, isn't it?

@MaxGraey Yes it is

@weswigham weswigham added the Waiting for TC39 Unactionable until TC39 reaches some conclusion label Nov 6, 2018
@RyanCavanaugh
Copy link
Member

Closing since there's nothing for us to do but wait for TC39

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ES Next New featurers for ECMAScript (a.k.a. ESNext) Suggestion An idea for TypeScript Waiting for TC39 Unactionable until TC39 reaches some conclusion
Projects
None yet
Development

No branches or pull requests

6 participants