typescript 在测试 $componentController 时抱怨调用签名

typescript complains about call signature when testing $componentController

我正在尝试测试 angular 1.5 组件,但 Typescript 在控制台中显示红色。

(17,27): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'IComponentOptions' has no compatible call signatures. PhantomJS 2.1.1 (Windows 8 0.0.0) Component: RecipeContainer should have a defined component FAILED

我是否错误地包含了文件? (我是用webpack编译的)

我是否缺少类型定义?

任何帮助将不胜感激,现在我已经挠头好几个小时了。


规格文件:

import * as angular from 'angular';
import 'angular-mocks';

import { RecipeContainer } from './recipe-container.component';
import { recipes } from '../recipe-store';

describe('Component: RecipeContainer', () => {
    let $componentController: ng.IComponentOptions;

    beforeEach(angular.mock.module('app'));
    beforeEach(angular.mock.inject((_$componentController_: ng.IComponentOptions) => {
        $componentController = _$componentController_;
    }));

    it('should have a defined component', () => {
        const bindings = { recipes };
        const component = $componentController('RecipeContainer', null, bindings); //webstorm underlines this line 
        expect(component).toBeDefined();
    });
});

component.ts:

class RecipeContainerController implements ng.IComponentController {
    constructor(private $log: ng.ILogService) {
    }
    $onInit() {
        this.$log.info('inside onInit');
    }
}

export const RecipeContainer: ng.IComponentOptions = {
    bindings: {
        recipes: '<'
    },

    controller: RecipeContainerController,

    template: '<div>hello</div>'
};

$componentControllerIComponentControllerService type。不是 IComponentOptions。如果您在变量上使用了错误的类型,TypeScript 类型系统会报错。

应该是

beforeEach(angular.mock.inject((_$componentController_: ng.IComponentControllerService) => {
  ...