Files
scriptc/tests/corpus/6391-nullish-function-default.ts
T
Malte UblandClaude Opus 5.5 c17eec0261 Compile event-loop metrics, predicate-narrowed catch bindings and other wrapper-reachable gaps
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>
2026-10-19 19:04:07 -07:00

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));