Evaluate compile-time constants
See original GitHub issueTypeScript Version: 3.5.0-dev.20190511
Search Terms:
compile-time operations numerical constants
Code
main.ts
const TWO: 2 = 1 + 1;
Expected behavior:
Transpiles without error
Actual behavior:
$> tsc main.ts
main.ts:1:7 - error TS2322: Type ‘number’ is not assignable to type ‘2’.
Playground Link:
https://www.typescriptlang.org/play/#src=const TWO%3A 2 %3D 1 %2B 1%3B
Related Issues:
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Compile-time constants, constant expressions, and constexpr
The compiler is only required to evaluate constant expressions at compile time in contexts where a value is actually required at compile-time.
Read more >What are Compile-time Constants in Java?
Expressions like these are called constant expressions, as the compiler will calculate them and produce a single compile-time constant.
Read more >Constant Evaluation - The Rust Reference
Constant evaluation is the process of computing the result of expressions during compilation. Only a subset of all expressions can be evaluated at...
Read more >Runtime and Compile-time constants in C++
Run-time Constant: These are the constants whose respective values can only be known or computed at the time of running of source code....
Read more >[Pitch] Compile-Time Constant Values
Compile -time constant values are values that can be known or computed during compilation and are guaranteed to not change after compilation. Use ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/Morglod/tsts
Currently working on comptime transformer
to
Even if MESSAGE_BYTES is a constant used in another part of the program?