diff --git a/types/ember/index.d.ts b/types/ember/index.d.ts index 61bdcb9828..32f4f7be05 100755 --- a/types/ember/index.d.ts +++ b/types/ember/index.d.ts @@ -18,6 +18,18 @@ declare module 'ember' { import Rsvp from 'rsvp'; import { TemplateFactory } from 'htmlbars-inline-precompile'; + // A type registry for Ember `Service`s. Meant to be declaration-merged so + // string lookups resolve to the correct type. + export interface ServiceRegistry { + [serviceName: string]: Ember.Service; + } + + // A type registry for Ember `Controller`s. Meant to be declaration-merged + // so string lookups resolve to the correct type. + export interface ControllerRegistry { + [controllerName: string]: Ember.Controller; + } + // Get an alias to the global Array type to use in inner scope below. type GlobalArray = T[]; @@ -2340,12 +2352,16 @@ declare module 'ember' { * Creates a property that lazily looks up another controller in the container. * Can only be used when defining another controller. */ - function controller(name?: string): ComputedProperty; + function controller( + name?: K + ): ComputedProperty; /** * Creates a property that lazily looks up a service in the container. There * are no restrictions as to what objects a service can be injected into. */ - function service(name?: string): ComputedProperty; + function service( + name?: K + ): ComputedProperty; } namespace ENV { const EXTEND_PROTOTYPES: typeof Ember.EXTEND_PROTOTYPES; diff --git a/types/ember/test/inject.ts b/types/ember/test/inject.ts index dd628f6d2a..5afc159ec4 100755 --- a/types/ember/test/inject.ts +++ b/types/ember/test/inject.ts @@ -8,9 +8,19 @@ class ApplicationController extends Ember.Controller { transitionToLogin() {} } +declare module 'ember' { + interface ServiceRegistry { + auth: AuthService; + } + + interface ControllerRegistry { + application: ApplicationController; + } +} + class LoginRoute extends Ember.Route { - auth = Ember.inject.service('authentication') as Ember.ComputedProperty; - application = Ember.inject.controller() as Ember.ComputedProperty; + auth = Ember.inject.service('auth'); + application = Ember.inject.controller('application'); didTransition() { if (!this.get('auth').get('isAuthenticated')) {