Files
scriptc/tests/corpus/class-never-getter.ts
T
Malte UblandClaude Opus 5.5 b831d840d7 Accept getters that never return a value
A getter that only throws (`get page(): never`, or Next.js's unannotated
removed-API getters) or has no return statement declared a VOID property
type, so the class was refused (SC2001). No read of such a getter produces
a value other than undefined; the property now takes the checked-dynamic
slot, and each read throws the getter's error or answers undefined.

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

37 lines
907 B
TypeScript

// A getter that never returns a value compiles: annotated `never` or
// unannotated (the removed-API getter idiom, which throws), and a getter
// without a return statement, whose reads answer undefined.
class Req {
ok = 1;
get page(): never {
throw new Error("page has been removed");
}
get ua(): never {
throw new TypeError("ua has been removed");
}
public get legacy() {
throw new RangeError("legacy has been removed");
}
get nothing() {
return;
}
}
const r = new Req();
try {
console.log(r.page);
} catch (e) {
console.log(e instanceof Error ? `${e.name}: ${e.message}` : e);
}
try {
const ua = r.ua;
console.log("unreachable", ua);
} catch (e) {
console.log(e instanceof Error ? `${e.name}: ${e.message}` : e);
}
try {
console.log(r.legacy);
} catch (e) {
console.log(e instanceof Error ? `${e.name}: ${e.message}` : e);
}
console.log(r.ok, r.nothing);