Files
scriptc/tests/corpus/symbol-class-fields.ts
Chris Tate c58160ca94 Support stable symbol-keyed class fields
- Compile initialized Symbol() and Symbol.for() fields, including inherited OpenTUI brands.
- Share registry-key storage across modules and keep symbol slots out of string-keyed enumeration.
- Refuse unstable keys and unsupported symbol-field copies.
2026-09-27 22:47:14 -05:00

16 lines
420 B
TypeScript

const brand: unique symbol = Symbol.for("scriptc.typed.brand");
const text: unique symbol = Symbol("text");
class Typed {
[brand]: boolean = true;
[text]: string | undefined = undefined;
read(): boolean {
return this[brand];
}
}
const typed = new Typed();
console.log(typed[brand], typed[text], typed.read());
typed[brand] = false;
typed[text] = "set";
console.log(typed[brand], typed[text], typed.read());