From 5154d22df9ab2dc42e5b640ac5f29a1142b0bb8c Mon Sep 17 00:00:00 2001 From: crisbeto Date: Wed, 17 Oct 2018 11:17:57 +0200 Subject: [PATCH] feat: add support for noImplicitThis Adds support for the `noImplicitThis` compiler option and fixes the compilation errors. --- e2e/tsconfig.json | 1 + e2e/util/asserts.ts | 2 +- src/bazel-tsconfig-build.json | 1 + src/cdk-experimental/tsconfig-build.json | 1 + .../interactivity-checker.spec.ts | 2 +- src/cdk/a11y/key-manager/list-key-manager.spec.ts | 12 ++++++++---- src/demo-app/tsconfig-aot.json | 1 + src/demo-app/tsconfig-build.json | 1 + src/e2e-app/tsconfig-build.json | 1 + src/lib/tsconfig-build.json | 1 + src/material-examples/tsconfig-build.json | 1 + src/material-experimental/tsconfig-build.json | 1 + src/material-moment-adapter/tsconfig-build.json | 1 + src/universal-app/tsconfig-build.json | 1 + src/universal-app/tsconfig-prerender.json | 1 + test/angular-test-init-spec.ts | 2 +- tools/dashboard/functions/tsconfig.json | 1 + tools/dgeni/tsconfig.json | 1 + tools/gulp/tasks/docs.ts | 6 +++--- tools/gulp/tsconfig.json | 1 + tsconfig.json | 1 + 21 files changed, 30 insertions(+), 10 deletions(-) diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json index 17bd80a77063..00a2fb783dff 100644 --- a/e2e/tsconfig.json +++ b/e2e/tsconfig.json @@ -7,6 +7,7 @@ "experimentalDecorators": true, "strictNullChecks": true, "strictFunctionTypes": true, + "noImplicitThis": true, "inlineSources": true, "lib": ["es2015"], "module": "commonjs", diff --git a/e2e/util/asserts.ts b/e2e/util/asserts.ts index d508ca7c79ca..70467ffe2c9d 100644 --- a/e2e/util/asserts.ts +++ b/e2e/util/asserts.ts @@ -34,6 +34,6 @@ export function expectLocation(element: FinderResult, {x, y}: Point): void { */ export function expectAlignedWith(element: FinderResult, otherElement: FinderResult): void { getElement(otherElement).getLocation().then((location: Point) => { - this.expectLocation(getElement(element), location); + expectLocation(getElement(element), location); }); } diff --git a/src/bazel-tsconfig-build.json b/src/bazel-tsconfig-build.json index b4d1b104343b..aefd403c67f7 100644 --- a/src/bazel-tsconfig-build.json +++ b/src/bazel-tsconfig-build.json @@ -13,6 +13,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "importHelpers": true, "newLine": "lf", "module": "es2015", diff --git a/src/cdk-experimental/tsconfig-build.json b/src/cdk-experimental/tsconfig-build.json index c0029abe6b90..ff560dedc537 100644 --- a/src/cdk-experimental/tsconfig-build.json +++ b/src/cdk-experimental/tsconfig-build.json @@ -9,6 +9,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "importHelpers": true, "newLine": "lf", "module": "es2015", diff --git a/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts b/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts index 6ccc136d5248..2d9953c919cd 100644 --- a/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts +++ b/src/cdk/a11y/interactivity-checker/interactivity-checker.spec.ts @@ -509,7 +509,7 @@ describe('InteractivityChecker', () => { } } - function runIf(condition: boolean, runFn: Function): () => void { + function runIf(this: any, condition: boolean, runFn: Function): () => void { return (...args: any[]) => { if (condition) { runFn.apply(this, args); diff --git a/src/cdk/a11y/key-manager/list-key-manager.spec.ts b/src/cdk/a11y/key-manager/list-key-manager.spec.ts index b3c9c3b65e57..83966bbea41b 100644 --- a/src/cdk/a11y/key-manager/list-key-manager.spec.ts +++ b/src/cdk/a11y/key-manager/list-key-manager.spec.ts @@ -37,6 +37,10 @@ class FakeQueryList extends QueryList { notifyOnChanges() { this.changes.next(this); } } +interface KeyEventTestContext { + nextKeyEvent: KeyboardEvent; + prevKeyEvent: KeyboardEvent; +} describe('Key managers', () => { let itemList: FakeQueryList; @@ -164,7 +168,7 @@ describe('Key managers', () => { expect(fakeKeyEvents.downArrow.defaultPrevented).toBe(false); }); - describe('with `vertical` direction', () => { + describe('with `vertical` direction', function(this: KeyEventTestContext) { beforeEach(() => { keyManager.withVerticalOrientation(); this.nextKeyEvent = createKeyboardEvent('keydown', DOWN_ARROW); @@ -174,7 +178,7 @@ describe('Key managers', () => { runDirectionalKeyTests.call(this); }); - describe('with `ltr` direction', () => { + describe('with `ltr` direction', function(this: KeyEventTestContext) { beforeEach(() => { keyManager.withHorizontalOrientation('ltr'); this.nextKeyEvent = createKeyboardEvent('keydown', RIGHT_ARROW); @@ -184,7 +188,7 @@ describe('Key managers', () => { runDirectionalKeyTests.call(this); }); - describe('with `rtl` direction', () => { + describe('with `rtl` direction', function(this: KeyEventTestContext) { beforeEach(() => { keyManager.withHorizontalOrientation('rtl'); this.nextKeyEvent = createKeyboardEvent('keydown', LEFT_ARROW); @@ -199,7 +203,7 @@ describe('Key managers', () => { * parameters have to be passed in via Jasmine's context object (`this` inside a `beforeEach`) * because this function has to run before any `beforeEach`, `beforeAll` etc. hooks. */ - function runDirectionalKeyTests() { + function runDirectionalKeyTests(this: KeyEventTestContext) { it('should set subsequent items as active when the next key is pressed', () => { keyManager.onKeydown(this.nextKeyEvent); diff --git a/src/demo-app/tsconfig-aot.json b/src/demo-app/tsconfig-aot.json index 1a78a695cd8b..4558ce9a660c 100644 --- a/src/demo-app/tsconfig-aot.json +++ b/src/demo-app/tsconfig-aot.json @@ -10,6 +10,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "outDir": "../../dist/packages/demo-app", "rootDirs": [ ".", diff --git a/src/demo-app/tsconfig-build.json b/src/demo-app/tsconfig-build.json index 7c0cbee51bac..97522f7746f3 100644 --- a/src/demo-app/tsconfig-build.json +++ b/src/demo-app/tsconfig-build.json @@ -10,6 +10,7 @@ "noUnusedParameters": true, "strictNullChecks": true, "strictFunctionTypes": true, + "noImplicitThis": true, "lib": ["es6", "es2015", "dom"], "skipLibCheck": true, "module": "commonjs", diff --git a/src/e2e-app/tsconfig-build.json b/src/e2e-app/tsconfig-build.json index c41f2f49b87d..caefeb7e882d 100644 --- a/src/e2e-app/tsconfig-build.json +++ b/src/e2e-app/tsconfig-build.json @@ -10,6 +10,7 @@ // strict-null compliant. "strictNullChecks": false, "strictFunctionTypes": true, + "noImplicitThis": true, "lib": ["es6", "es2015", "dom"], "module": "commonjs", "moduleResolution": "node", diff --git a/src/lib/tsconfig-build.json b/src/lib/tsconfig-build.json index 650d784545b9..f38795e4693c 100644 --- a/src/lib/tsconfig-build.json +++ b/src/lib/tsconfig-build.json @@ -8,6 +8,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "importHelpers": true, "newLine": "lf", "module": "es2015", diff --git a/src/material-examples/tsconfig-build.json b/src/material-examples/tsconfig-build.json index 4a4e4c1adc66..7b20aef699e4 100644 --- a/src/material-examples/tsconfig-build.json +++ b/src/material-examples/tsconfig-build.json @@ -11,6 +11,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "importHelpers": true, "module": "es2015", "moduleResolution": "node", diff --git a/src/material-experimental/tsconfig-build.json b/src/material-experimental/tsconfig-build.json index 0f506de7c51a..b009c8f7e457 100644 --- a/src/material-experimental/tsconfig-build.json +++ b/src/material-experimental/tsconfig-build.json @@ -9,6 +9,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "importHelpers": true, "newLine": "lf", "module": "es2015", diff --git a/src/material-moment-adapter/tsconfig-build.json b/src/material-moment-adapter/tsconfig-build.json index c73a5c413692..bbfdb1906025 100644 --- a/src/material-moment-adapter/tsconfig-build.json +++ b/src/material-moment-adapter/tsconfig-build.json @@ -11,6 +11,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "importHelpers": true, "newLine": "lf", "module": "es2015", diff --git a/src/universal-app/tsconfig-build.json b/src/universal-app/tsconfig-build.json index 63c7dac01422..4b59f1b671b5 100644 --- a/src/universal-app/tsconfig-build.json +++ b/src/universal-app/tsconfig-build.json @@ -9,6 +9,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "module": "commonjs", "moduleResolution": "node", "outDir": ".", diff --git a/src/universal-app/tsconfig-prerender.json b/src/universal-app/tsconfig-prerender.json index 5ec5434fac82..bccab972099d 100644 --- a/src/universal-app/tsconfig-prerender.json +++ b/src/universal-app/tsconfig-prerender.json @@ -8,6 +8,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "module": "commonjs", "moduleResolution": "node", "outDir": ".", diff --git a/test/angular-test-init-spec.ts b/test/angular-test-init-spec.ts index 91e783d5bac5..a2bd5a3c2177 100644 --- a/test/angular-test-init-spec.ts +++ b/test/angular-test-init-spec.ts @@ -38,7 +38,7 @@ function patchTestBedToDestroyFixturesAfterEveryTest(testBedInstance: TestBed) { // Monkey-patch the resetTestingModule to destroy fixtures outside of a try/catch block. // With https://github.com/angular/angular/commit/2c5a67134198a090a24f6671dcdb7b102fea6eba // errors when destroying components are no longer causing Jasmine to fail. - testBedInstance.resetTestingModule = function() { + testBedInstance.resetTestingModule = function(this: {_activeFixtures: ComponentFixture[]}) { try { this._activeFixtures.forEach((fixture: ComponentFixture) => fixture.destroy()); } finally { diff --git a/tools/dashboard/functions/tsconfig.json b/tools/dashboard/functions/tsconfig.json index 7869e33a5088..755a3821a92c 100644 --- a/tools/dashboard/functions/tsconfig.json +++ b/tools/dashboard/functions/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "strictNullChecks": true, "strictFunctionTypes": true, + "noImplicitThis": true, "sourceMap": true, "target": "es5", "baseUrl": "", diff --git a/tools/dgeni/tsconfig.json b/tools/dgeni/tsconfig.json index 594fe954aaf7..51687179ecfa 100644 --- a/tools/dgeni/tsconfig.json +++ b/tools/dgeni/tsconfig.json @@ -8,6 +8,7 @@ "outDir": "../../dist/tools/dgeni", "strictNullChecks": true, "strictFunctionTypes": true, + "noImplicitThis": true, "noEmitOnError": true, "noImplicitAny": true, "target": "es5", diff --git a/tools/gulp/tasks/docs.ts b/tools/gulp/tasks/docs.ts index 9a356d387ab0..37a2fd6de5e9 100644 --- a/tools/gulp/tasks/docs.ts +++ b/tools/gulp/tasks/docs.ts @@ -204,11 +204,11 @@ function fixMarkdownDocLinks(link: string, filePath: string): string { * @param classPrefix The prefix to use for the alias class. */ function createTagNameAliaser(classPrefix: string) { - return function() { + return function(this: HTMLElement) { MARKDOWN_TAGS_TO_CLASS_ALIAS.forEach(tag => { - for (let el of this.querySelectorAll(tag)) { + Array.from(this.querySelectorAll(tag)).forEach(el => { el.classList.add(`${classPrefix}-${tag}`); - } + }); }); return this; diff --git a/tools/gulp/tsconfig.json b/tools/gulp/tsconfig.json index 96ae0329ca1e..2db82ffaece1 100644 --- a/tools/gulp/tsconfig.json +++ b/tools/gulp/tsconfig.json @@ -8,6 +8,7 @@ "outDir": "../../dist/tools/gulp", "strictNullChecks": true, "strictFunctionTypes": true, + "noImplicitThis": true, "noEmitOnError": true, "noImplicitAny": true, "target": "es5", diff --git a/tsconfig.json b/tsconfig.json index 3b29a0f200a2..33b6ea674ea2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "strictNullChecks": true, "strictFunctionTypes": true, "noImplicitAny": true, + "noImplicitThis": true, "skipLibCheck": true, "target": "es2015", "lib": ["es5", "es2015", "dom"],