mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
`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>
20 lines
635 B
TypeScript
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));
|