Skip to content

Commit 5070508

Browse files
committed
Types: resolve services with Owner.lookup
Integrate the service registry into the `DIRegistry` introduced as part of rationalizing the `Owner` types in PR #20271 (94276b5). This allows `Owner.lookup('service:foo')` to resolve a `FooService` if one is set up in the `@ember/service` module's `Registry` interface. The preview types already used this mechanic (as of 5658b13), so this just means that when we ship the stable (i.e. built from source) version of `@ember/service`, it will *continue* working. Meta: Shipping this implementation for the lookup was blocked on being able to publish type modules with `declare module`, which was implemented in PR #20316 (9adcd15). We will likely need to rework other parts of the type hierarchy to support publishing from source.
1 parent 19d66a8 commit 5070508

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/@ember/service/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,16 @@ export function service(
9393
export default class Service extends FrameworkObject {
9494
static isServiceFactory = true;
9595
}
96+
97+
/**
98+
A type registry for Ember `Service`s. Meant to be declaration-merged so string
99+
lookups resolve to the correct type.
100+
*/
101+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
102+
export interface Registry extends Record<string, Service> {}
103+
104+
declare module '@ember/owner' {
105+
export interface DIRegistry {
106+
service: Registry;
107+
}
108+
}

0 commit comments

Comments
 (0)