Files
scriptc/tests/diagnostics/comptime.ts
2026-07-22 18:08:04 -05:00

23 lines
620 B
TypeScript

// tsc-clean misuses of comptime: the callback must be an inline function
// literal with no references to outer bindings, it must not throw or time
// out, and its result must bake as a finite literal of the expected type.
const limit = 4;
const captured = comptime(() => limit * 2);
function make(): number {
return 3;
}
const viaRef = comptime(make);
const thrown = comptime((): number => {
throw "boom at compile time";
});
const nan = comptime(() => 0 / 0);
const nested = comptime(() => comptime(() => 1));
const eventually = comptime(async () => 1);
const lied = comptime(() => 1 as unknown as string);