Skip to content

Commit

Permalink
Types: resolve services with Owner.lookup
Browse files Browse the repository at this point in the history
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, 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.
  • Loading branch information
chriskrycho committed Dec 9, 2022
1 parent 19d66a8 commit 5a41a05
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/@ember/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ export function service(
export default class Service extends FrameworkObject {
static isServiceFactory = true;
}

/**
A type registry for Ember `Service`s. Meant to be declaration-merged so string
lookups resolve to the correct type.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Registry extends Record<string, Service> {}

declare module '@ember/owner' {
export interface DIRegistry {
service: Registry;
}
}

0 comments on commit 5a41a05

Please sign in to comment.