mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
A function expression's or arrow's parameter and return types commit at the statement that holds it, and a generic instance's at the instance drain. Both are now localized-failure commit points for declaration slots: the failing type degrades and the statement or instance lowers again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
// Localized failure, stage L2: parameters and returns of arrows, function
|
|
// expressions and generic instances become checked dynamic slots.
|
|
type Hook = Map<string, (x: number) => string> | AbortSignal | (() => number) | Set<string>;
|
|
|
|
interface Model<T> {
|
|
id: T;
|
|
hook: Hook;
|
|
}
|
|
|
|
function retry<T>(label: string, request: () => Promise<T> | Hook): T | string {
|
|
const r = request();
|
|
return typeof r === "function" ? label + ":" + String(r()) : label + ":other";
|
|
}
|
|
|
|
function describe<T>(model: Model<T>): string {
|
|
return `${String(model.id)}/${model.hook instanceof Set ? model.hook.size : typeof model.hook}`;
|
|
}
|
|
|
|
const run = (hook: Hook, n: number): string => (typeof hook === "function" ? String(hook() + n) : "set");
|
|
const make = function (size: number): Hook {
|
|
return new Set(Array.from({ length: size }, (_, i) => `k${i}`));
|
|
};
|
|
|
|
console.log(run(() => 40, 2), run(new Set(["a"]), 1));
|
|
const h = make(3);
|
|
console.log(h instanceof Set ? h.size : -1);
|
|
console.log(retry("a", () => () => 7), retry<number>("b", () => new Set<string>()));
|
|
console.log(describe({ id: 5, hook: new Set(["x", "y"]) }), describe({ id: "s", hook: () => 1 }));
|