-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Evaluate compile-time constants #31352
Comments
Fun times: const TWO: 2 = (1 + 3) as 2;
console.log(TWO); Transpiles and executes, printing
EDIT: Please ignore this one |
Type-assertions are a way to tell the compiler: "Trust me on this, I know what I'm doing and what this type is". The compiler trusts you. In this case the compiler resolves the type |
Duplicate of #15645 |
Without some motivating use cases this doesn't look compelling as an area of investment. The intersection of areas where you have a finite domain of numbers (literals) but want to do some computation to map to one of those members seems very small. |
const MESSAGE_BYTES = 32;
const BYTE_BITS = 8;
type SHA3Size = 224 | 256 | 384 | 512;
const SHA3_SIZE : SHA3Size = MESSAGE_BYTES * BYTE_BITS;
const hasher = SHA3(SHA3_SIZE) I would understand if this not compelling enough. |
|
Even if MESSAGE_BYTES is a constant used in another part of the program? |
https://github.com/Morglod/tsts 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);
}); to const result = (() => { return (36); })(); |
This issue has been marked as "Too Complex" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.5.0-dev.20190511
Search Terms:
compile-time operations numerical constants
Code
Expected behavior:
Transpiles without error
Actual behavior:
Playground Link:
https://www.typescriptlang.org/play/#src=const%20TWO%3A%202%20%3D%201%20%2B%201%3B
Related Issues:
The text was updated successfully, but these errors were encountered: