VS2015 AngularJS Typescript 定义未完全正常工作

VS2015 AngularJS Typescript definition not fully working

我已经安装了 Angular TypeScript 定义类型 (VS2015)。 打字似乎主要起作用,包括 HTML 或 "angular." 中的 "ng-" 指令将起作用但是当我尝试对注入变量(例如 $scope)使用智能感知时......没有运气和智能感知不显示。

这是 DefinitelyTyped https://github.com/borisyankov/DefinitelyTyped 库的限制还是它应该起作用?

我用接口 ng.IScope 注释了 $scope。编译器现在知道 $scope 有方法

function Controller($scope: ng.IScope) {
    $scope.$broadcast('myEvent');
    $scope.title = 'Yabadabadu';
}

它不能开箱即用,因为您可以向 $scope 对象添加任何东西。

我认为有两种方法可以让编译器开心。第一种方式需要更少的输入:

function Controller($scope: ng.IScope) {
    $scope.$broadcast('myEvent');
    $scope['title'] = 'Yabadabadu';
}

第二种方式是:

interface IMyScope extends ng.IScope {
  title: string;
}

function Controller($scope: IMyScope) {
    $scope.$broadcast('myEvent');
    $scope.title = 'Yabadabadu';
}

我对简单指令使用第一种方法,对更复杂的指令使用第二种方法。