mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-14 04:39:43 +08:00
23 lines
620 B
TypeScript
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);
|