Files
scriptc/tests/corpus/generic-undefined-argument.ts
T
Malte UblandClaude Opus 5.5 cd63b935e0 Instantiate generics with a literal undefined argument
`id(undefined)` binds T = undefined, which the type mapper answers as VOID
(the return convention), so the instance's parameter was refused (SC2001)
although a declared `v: undefined` parameter compiles. Instantiated
parameters are value positions and now take the unit-only slot, as
declared ones do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 15:16:18 -07:00

20 lines
635 B
TypeScript

// A generic call with a literal `undefined` argument binds T = undefined;
// the parameter holds undefined like a declared `v: undefined` parameter.
function kind<T>(v: T): string {
return typeof v;
}
console.log(kind(undefined), kind(null), kind(1), kind("s"));
function same<T>(a: T, b: T): boolean {
return a === b;
}
console.log(same(undefined, undefined));
function wrap<T>(v: T): { v: T } {
return { v };
}
const w = wrap(undefined);
console.log(JSON.stringify(w), w.v === undefined, "v" in w);
function describe<T>(label: string, v: T): string {
return `${label}=${String(v)}`;
}
console.log(describe("u", undefined));