Interfaces for scope property in Directive and bindings property in Component to avoid using simple Object (not descriptive enough) and the explicit type {[binding: string]: string} which is too verbose.
The $onChanges method of the IComponentController interface has the type in-lined, making it impossible to refer to it. A new interface was added to encapsulate this type, so that it can be easily used and extended.
In angular you can either write `directive('myDirective', ['$http', function($http) {...}])`, which is minification safe, but it's also possible to write `directive('myDirective', function($http) {...})` which might not be minification safe, but valid angular nonetheless.
A couple of additional optional parameters were added to the `$transclude`
function when support for multi-slot transclusion was added in Angular 1.5 [1].
This commit updates the `ITranscludeFunction` type definition to reflect those
changes.
[1] https://docs.angularjs.org/api/ng/service/$compile#-controller-
Rename name property from ng.IDirective as there is no mention of this property in the official API documentation (https://docs.angularjs.org/api/ng/service/$compile) and it was causing issues with directives made as classes like so:
class MyDirective implements ng.IDirective {
public template = "<div>{{ test }}</div>";
public scope = {
test: "="
};
public static name = "myDirective";
public static $inject: string[] = ["$http"];
constructor(private $http: ng.IHttpService) {
}
public link(scope: IDirectiveScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) {
}
}
angular.module("app")
.directive(MyDirective.name, DirectiveFactory.getFactoryFor(UserProjectRoles));
See http://stackoverflow.com/questions/38853868/typeerror-when-class-has-static-member-name for more details.
Changing it to another non-reserved name fixes the issue.
Typescript 2.0 starts checking the compatibility of the index
signature with the base JQuery interface; Hence we are forced to
return Document & HTMLElement to be compatible with the base.
JQ(lite)-unwrapping $document[0] should be of type Document instead of
the default HTMLElement. Otherwise important methods like
getElementById are missing.
Angular 1.5+ component Controllers have four new lifecycle hooks:
$onInit()
$onDestroy()
$onChanges(...)
$postInit()
There is currently no reference to any of then in the definitions files.
I added an additional interface to the component's controller type that defines the new hooks with the official documentation from docs.angularjs.org
I recently came up with this solution so I could leverage my custom scope when grabbing the scope from a controller using angular.element. It works well and with the <T extends IScope> it ensures that you can only set it to an interface that extends IScope.