//This is unfortunately a duplicate of the old implementation in customizable.ts. Consider refactoring //that to use this implementation once the revised UI is more stable. export class ServiceRegistry { private constructor(private registry: T) { } register(key: K, service: S): ServiceRegistry & T> { //Add service to registry and return the same object with a narrowed type. (this.registry as any)[key] = service; return this as any as ServiceRegistry & T>; } get(key: K): T[K] { if (!(key in this.registry)) { throw new Error('Invalid service key: ' + String(key)); } return this.registry[key]; } has(key: K): boolean { return key in this.registry; } static init(): ServiceRegistry<{}> { return new ServiceRegistry({}); } }