AngularJS: compatibility with strictFunctionTypes

Fixes #21160
This commit is contained in:
Georgii Dolzhykov 2017-11-01 13:31:40 +03:00
parent 17f38a9945
commit 44e215bda7
4 changed files with 38 additions and 31 deletions

View File

@ -707,7 +707,7 @@ class SampleDirective implements ng.IDirective {
restrict = 'A';
name = 'doh';
compile(templateElement: ng.IAugmentedJQuery) {
compile(templateElement: JQLite) {
return {
post: this.link
};
@ -723,7 +723,7 @@ class SampleDirective implements ng.IDirective {
class SampleDirective2 implements ng.IDirective {
restrict = 'EAC';
compile(templateElement: ng.IAugmentedJQuery) {
compile(templateElement: JQLite) {
return {
pre: this.link
};
@ -741,7 +741,7 @@ angular.module('SameplDirective', []).directive('sampleDirective', SampleDirecti
angular.module('AnotherSampleDirective', []).directive('myDirective', ['$interpolate', '$q', ($interpolate: ng.IInterpolateService, $q: ng.IQService) => {
return {
restrict: 'A',
link: (scope: ng.IScope, el: ng.IAugmentedJQuery, attr: ng.IAttributes) => {
link: (scope: ng.IScope, el: JQLite, attr: ng.IAttributes) => {
$interpolate(attr['test'])(scope);
$interpolate('', true)(scope);
$interpolate('', true, 'html')(scope);
@ -869,7 +869,7 @@ angular.module('docsTimeDirective', [])
}])
.directive('myCurrentTime', ['$interval', 'dateFilter', ($interval: any, dateFilter: any) => {
return {
link(scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) {
link(scope: ng.IScope, element: JQLite, attrs: ng.IAttributes) {
let format: any;
let timeoutId: any;
@ -916,7 +916,7 @@ angular.module('docsTransclusionExample', [])
transclude: true,
scope: {},
templateUrl: 'my-dialog.html',
link(scope: ng.IScope, element: ng.IAugmentedJQuery) {
link(scope: ng.IScope, element: JQLite) {
scope['name'] = 'Jeff';
}
};
@ -1017,7 +1017,7 @@ angular.module('docsTabsExample', [])
scope: {
title: '@'
},
link(scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, tabsCtrl: any) {
link(scope: ng.IScope, element: JQLite, attrs: ng.IAttributes, tabsCtrl: any) {
tabsCtrl.addPane(scope);
},
templateUrl: 'my-pane.html'
@ -1098,6 +1098,18 @@ angular.module('copyExample', [])
$scope.reset();
}]);
// Extending IScope for a directive, see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/21160
interface IMyScope extends angular.IScope {
myScopeProperty: boolean;
}
angular.module('aaa').directive('directive', () => ({
link(scope: IMyScope) {
console.log(scope.myScopeProperty);
return;
}
}));
namespace locationTests {
const $location: ng.ILocationService = null;

View File

@ -9,9 +9,6 @@
/// <reference path="jqlite.d.ts" />
// NOTE: @types/angular technically doesn't require TypeScript 2.3, only TypeScript 2.1.
// It has a TypeScript 2.3 header so that merging tests with @types/jquery v3 will work.
declare var angular: angular.IAngularStatic;
// Support for painless dependency injection
@ -232,8 +229,8 @@ declare namespace angular {
* @param name Name of the directive in camel-case (i.e. ngBind which will match as ng-bind)
* @param directiveFactory An injectable directive factory function.
*/
directive(name: string, directiveFactory: Injectable<IDirectiveFactory>): IModule;
directive(object: {[directiveName: string]: Injectable<IDirectiveFactory>}): IModule;
directive<TScope extends IScope>(name: string, directiveFactory: Injectable<IDirectiveFactory<TScope>>): IModule;
directive<TScope extends IScope>(object: {[directiveName: string]: Injectable<IDirectiveFactory<TScope>>}): IModule;
/**
* Register a service factory, which will be called to return the service instance. This is short for registering a service where its provider consists of only a $get property, which is the given service factory function. You should use $provide.factory(getFn) if you do not need to configure your service in a provider.
*
@ -1252,8 +1249,8 @@ declare namespace angular {
}
interface ICompileProvider extends IServiceProvider {
directive(name: string, directiveFactory: Injectable<IDirectiveFactory>): ICompileProvider;
directive(object: {[directiveName: string]: Injectable<IDirectiveFactory>}): ICompileProvider;
directive<TScope extends IScope>(name: string, directiveFactory: Injectable<IDirectiveFactory<TScope>>): ICompileProvider;
directive<TScope extends IScope>(object: {[directiveName: string]: Injectable<IDirectiveFactory<TScope>>}): ICompileProvider;
component(name: string, options: IComponentOptions): ICompileProvider;
@ -1961,13 +1958,13 @@ declare namespace angular {
// and http://docs.angularjs.org/guide/directive
///////////////////////////////////////////////////////////////////////////
interface IDirectiveFactory {
(...args: any[]): IDirective | IDirectiveLinkFn;
interface IDirectiveFactory<TScope extends IScope = IScope> {
(...args: any[]): IDirective<TScope> | IDirectiveLinkFn<TScope>;
}
interface IDirectiveLinkFn {
interface IDirectiveLinkFn<TScope extends IScope = IScope> {
(
scope: IScope,
scope: TScope,
instanceElement: JQLite,
instanceAttributes: IAttributes,
controller?: IController | IController[] | {[key: string]: IController},
@ -1975,12 +1972,12 @@ declare namespace angular {
): void;
}
interface IDirectivePrePost {
pre?: IDirectiveLinkFn;
post?: IDirectiveLinkFn;
interface IDirectivePrePost<TScope extends IScope> {
pre?: IDirectiveLinkFn<TScope>;
post?: IDirectiveLinkFn<TScope>;
}
interface IDirectiveCompileFn {
interface IDirectiveCompileFn<TScope extends IScope> {
(
templateElement: JQLite,
templateAttributes: IAttributes,
@ -1991,11 +1988,11 @@ declare namespace angular {
* that is passed to the link function instead.
*/
transclude: ITranscludeFunction
): void | IDirectiveLinkFn | IDirectivePrePost;
): void | IDirectiveLinkFn<TScope> | IDirectivePrePost<TScope>;
}
interface IDirective {
compile?: IDirectiveCompileFn;
interface IDirective<TScope extends IScope = IScope> {
compile?: IDirectiveCompileFn<TScope>;
controller?: string | Injectable<IControllerConstructor>;
controllerAs?: string;
/**
@ -2004,7 +2001,7 @@ declare namespace angular {
* relies upon bindings inside a $onInit method on the controller, instead.
*/
bindToController?: boolean | {[boundProperty: string]: string};
link?: IDirectiveLinkFn | IDirectivePrePost;
link?: IDirectiveLinkFn<TScope> | IDirectivePrePost<TScope>;
multiElement?: boolean;
priority?: number;
/**
@ -2077,9 +2074,7 @@ declare namespace angular {
get<T>(name: '$xhrFactory'): IXhrFactory<T>;
has(name: string): boolean;
instantiate<T>(typeConstructor: {new(...args: any[]): T}, locals?: any): T;
invoke(inlineAnnotatedFunction: any[], context?: any, locals?: any): any;
invoke<T>(func: (...args: any[]) => T, context?: any, locals?: any): T;
invoke(func: Function, context?: any, locals?: any): any;
invoke<T = any>(func: Injectable<Function | ((...args: any[]) => T)>, context?: any, locals?: any): T;
strictDi: boolean;
}

View File

@ -16,7 +16,7 @@
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": false,
"strictFunctionTypes": false,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
@ -25,4 +25,4 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}
}

View File

@ -4,7 +4,7 @@ app.config(
['ngProgressLiteProvider',
(ngProgressLiteProvider: ng.progressLite.INgProgressLiteProvider) => {
ngProgressLiteProvider.settings.ease = 'ease';
ngProgressLiteProvider.settings.minimum = 0.08,
ngProgressLiteProvider.settings.minimum = 0.08;
ngProgressLiteProvider.settings.speed = 300;
ngProgressLiteProvider.settings.trickleRate = 0.02;
ngProgressLiteProvider.settings.trickleSpeed = 500;