/**
* Singleton — one instance, globally reachable, created on first use.
*/
class Registry {
private static instance: Registry | null = null;
private readonly entries = new Map<string, unknown>();
// The constructor is private, so `new Registry()` is a compile error.
// This is the whole trick: the class takes away your ability to make one.
private constructor() {}
static getInstance(): Registry {
if (Registry.instance === null) {
Registry.instance = new Registry();
}
return Registry.instance;
}
set(key: string, value: unknown): void {