Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Evaluate compile-time constants

See original GitHub issue

TypeScript Version: 3.5.0-dev.20190511

Search Terms:

compile-time operations numerical constants



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: TWO%3A 2 %3D 1 %2B 1%3B

Related Issues:

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

Morglodcommented, Apr 2, 2021

Currently working on comptime transformer

const numbers = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
const result = comptime(() => {
    return numbers.reduce((total, x) => sum(total, x), 0);


const result = (() => { return (36); })();
n0izn0izcommented, May 27, 2019

Even if MESSAGE_BYTES is a constant used in another part of the program?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found