mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
Once generic wrappers compile (#1413), the code behind them is reachable. This closes the general gaps found there: - performance.eventLoopUtilization() and monitorEventLoopDelay()'s IntervalHistogram (enable, disable, reset, percentile and the min, max, mean, stddev, count and exceeds readings), under the fallback declarations and @types/node. A new runtime unit, scr_perf_loop.c, links only for programs that read them (the perfLoop feature): an unref'd sampling interval records into HdrHistogram-shaped buckets, and utilization measures active time as the main thread's CPU time since the loop started. - Catch bindings narrowed by a user type predicate or an assertion read their members through the checked-dynamic value. - `??` with a function default of a different signature takes the optional callback's own function type and adapts the default. - Optional calls on interface-typed receivers dispatch like the plain protocol call. - `any` parameters of function declarations and spelled function types are checked-dynamic slots, and a generic instantiated at `any` takes `unknown` there. - `'key' in err` on Error receivers answers from the declaring subclasses. - Object.entries over a generic record resolves `keyof T extends never ? unknown : T[keyof T]` through the binding. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 lines
547 B
TypeScript
14 lines
547 B
TypeScript
// `??` with a function fallback whose signature differs from the optional
|
|
// callback's (fewer parameters, narrower result).
|
|
interface Opts {
|
|
tags?: (a: number, b: number) => Record<string, unknown>;
|
|
label?: (n: number) => string;
|
|
}
|
|
function run(o: Opts, x: number, y: number): string {
|
|
const tags = o.tags ?? (() => ({}));
|
|
const label = o.label ?? ((n: number) => `#${n}`);
|
|
return `${label(x)} ${JSON.stringify(tags(x, y))}`;
|
|
}
|
|
console.log(run({}, 1, 2));
|
|
console.log(run({ tags: (a, b) => ({ a, b }), label: (n) => `n${n}` }, 3, 4));
|