AndyPerlitch AndyPerlitch - 1 month ago 6
TypeScript Question

Overloading typescript interface definition for $injector.get in angular1 project

I am working on migrating an angular1 project from javascript to typescript, and would like to add to the overloaded $injector.get method to include the project's own injectable types. I read this typescript doc on merging interfaces. I added this into an imported d.ts file:

import TrendDisplayService from 'services/TrendDisplayService';
declare namespace angular {
export module ng.auto {
export interface IInjectorService {
get(name: 'trendDisplayService'): TrendDisplayService
}
}

}


However I am still seeing the "not assignable" type error when doing the following:

let trend:TrendDisplayService = $injector.get('trendDisplayService');


Any thoughts?

Answer

In the declaration module should be auto and not ng.auto.

declare namespace angular {
    export module auto {
        export interface IInjectorService {
            get(name: 'trendDisplayService'): TrendDisplayService
        }
    }
}