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

Having literals operations returning literals #29271

Closed
5 tasks done
npenin opened this issue Jan 5, 2019 · 3 comments
Closed
5 tasks done

Having literals operations returning literals #29271

npenin opened this issue Jan 5, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@npenin
Copy link

npenin commented Jan 5, 2019

Search Terms

enumassignmentcompat5.ts, ts2535

Suggestion

Currently, operations between literals are not considered as literals. It would bring much more flexibility to have this feature.

Use Cases

Operations on literals could help having better declarations and would help having more complex enums

Examples

// extract of enumassignmentcompat5.ts (which is not anymore in the repo BTW)
enum E {
    A, B, C
}
enum Computed {
    A = 1 << 1,
    B = 1 << 2,
    C = 1 << 3,
}
let ca: Computed.A = 1; // ok, because 1( left hand side operand) and 1 (right hand side operand) are literals, therefore, 1<<1 is also a literal.

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.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@NN---
Copy link

NN--- commented Jan 6, 2019

#15645 #26382

@weswigham weswigham added the Duplicate An existing issue was already created label Jan 7, 2019
@weswigham
Copy link
Member

See #15645 #26382 - thanks @NN---

@npenin
Copy link
Author

npenin commented Jan 8, 2019

indeed, thanks. It at least gives a new use case ;)

@npenin npenin closed this as completed Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants