From 5ec1717c58b56f0c07ea5043800fa36c3346f7c1 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 15 Nov 2017 08:43:35 -0800 Subject: [PATCH] fix: Update test code to type-check under TS 2.5 (#20175) PR Close #20175 --- integration/bazel/WORKSPACE | 2 +- packages/bazel/package.json | 2 +- .../test/metric/multi_metric_spec.ts | 2 +- .../test/reporter/json_file_reporter_spec.ts | 2 +- .../test/reporter/multi_reporter_spec.ts | 2 +- .../test/metadata/bundler_spec.ts | 2 +- .../test/metadata/typescript.mocks.ts | 3 ++ .../differs/iterable_differs_spec.ts | 6 ++-- packages/core/test/di/static_injector_spec.ts | 18 ++++++------ .../linker/jit_summaries_integration_spec.ts | 2 +- packages/examples/upgrade/static/ts/module.ts | 20 +++++++------ .../platform-server/test/integration_spec.ts | 28 +++++++++---------- .../src/web_workers/ui/location_providers.ts | 2 +- .../platform-webworker/src/worker_render.ts | 2 +- packages/router/src/router_module.ts | 2 +- .../upgrade/src/dynamic/upgrade_adapter.ts | 2 +- .../src/dynamic/upgrade_ng1_adapter.ts | 2 +- .../upgrade/src/static/upgrade_component.ts | 2 +- .../platform-webworker.d.ts | 2 +- 19 files changed, 55 insertions(+), 48 deletions(-) diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index bf231610f0..0809e8a6a5 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -3,7 +3,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "build_bazel_rules_nodejs", remote = "https://github.com/bazelbuild/rules_nodejs.git", - tag = "0.0.2", + tag = "0.2.1", ) load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories") diff --git a/packages/bazel/package.json b/packages/bazel/package.json index d756176a6a..6e8fcbc867 100644 --- a/packages/bazel/package.json +++ b/packages/bazel/package.json @@ -9,7 +9,7 @@ "typescript": ">=2.4.2 <2.6" }, "dependencies": { - "@bazel/typescript": "0.2.x", + "@bazel/typescript": "0.3.x", "@types/node": "6.0.84" }, "repository": { diff --git a/packages/benchpress/test/metric/multi_metric_spec.ts b/packages/benchpress/test/metric/multi_metric_spec.ts index 3d8ff95467..f8f8a9324f 100644 --- a/packages/benchpress/test/metric/multi_metric_spec.ts +++ b/packages/benchpress/test/metric/multi_metric_spec.ts @@ -17,7 +17,7 @@ export function main() { ids.map(id => ({provide: id, useValue: new MockMetric(id)})), MultiMetric.provideWith(ids) ]) - .get(MultiMetric); + .get(MultiMetric); return Promise.resolve(m); } diff --git a/packages/benchpress/test/reporter/json_file_reporter_spec.ts b/packages/benchpress/test/reporter/json_file_reporter_spec.ts index cbdbf5d9d4..6ca8647346 100644 --- a/packages/benchpress/test/reporter/json_file_reporter_spec.ts +++ b/packages/benchpress/test/reporter/json_file_reporter_spec.ts @@ -34,7 +34,7 @@ export function main() { } } ]; - return Injector.create(providers).get(JsonFileReporter); + return Injector.create(providers).get(JsonFileReporter); } it('should write all data into a file', diff --git a/packages/benchpress/test/reporter/multi_reporter_spec.ts b/packages/benchpress/test/reporter/multi_reporter_spec.ts index aa1502e36b..4c9e2c698a 100644 --- a/packages/benchpress/test/reporter/multi_reporter_spec.ts +++ b/packages/benchpress/test/reporter/multi_reporter_spec.ts @@ -17,7 +17,7 @@ export function main() { ids.map(id => ({provide: id, useValue: new MockReporter(id)})), MultiReporter.provideWith(ids) ]) - .get(MultiReporter); + .get(MultiReporter); return Promise.resolve(r); } diff --git a/packages/compiler-cli/test/metadata/bundler_spec.ts b/packages/compiler-cli/test/metadata/bundler_spec.ts index 5e150319a7..27d317492d 100644 --- a/packages/compiler-cli/test/metadata/bundler_spec.ts +++ b/packages/compiler-cli/test/metadata/bundler_spec.ts @@ -27,7 +27,7 @@ describe('metadata bundler', () => { const originalOne = './src/one'; const originalTwo = './src/two/index'; - expect(Object.keys(result.metadata.origins) + expect(Object.keys(result.metadata.origins !) .sort() .map(name => ({name, value: result.metadata.origins ![name]}))) .toEqual([ diff --git a/packages/compiler-cli/test/metadata/typescript.mocks.ts b/packages/compiler-cli/test/metadata/typescript.mocks.ts index 5b95e994c8..d63bd7a5c7 100644 --- a/packages/compiler-cli/test/metadata/typescript.mocks.ts +++ b/packages/compiler-cli/test/metadata/typescript.mocks.ts @@ -102,6 +102,7 @@ export class MockNode implements ts.Node { export class MockIdentifier extends MockNode implements ts.Identifier { public text: string; + public escapedText: ts.__String; // tslint:disable public _primaryExpressionBrand: any; public _memberExpressionBrand: any; @@ -137,12 +138,14 @@ export class MockVariableDeclaration extends MockNode implements ts.VariableDecl } export class MockSymbol implements ts.Symbol { + public escapedName: ts.__String; constructor( public name: string, private node: ts.Declaration = MockVariableDeclaration.of(name), public flags: ts.SymbolFlags = 0) {} getFlags(): ts.SymbolFlags { return this.flags; } getName(): string { return this.name; } + getEscapedName(): ts.__String { return this.escapedName; } getDeclarations(): ts.Declaration[] { return [this.node]; } getDocumentationComment(): ts.SymbolDisplayPart[] { return []; } // TODO(vicb): removed in TS 2.2 diff --git a/packages/core/test/change_detection/differs/iterable_differs_spec.ts b/packages/core/test/change_detection/differs/iterable_differs_spec.ts index 7d4b99be47..83a8230ce7 100644 --- a/packages/core/test/change_detection/differs/iterable_differs_spec.ts +++ b/packages/core/test/change_detection/differs/iterable_differs_spec.ts @@ -61,8 +61,10 @@ export function main() { const injector = Injector.create([{provide: IterableDiffers, useValue: parent}]); const childInjector = Injector.create([IterableDiffers.extend([factory2])], injector); - expect(injector.get(IterableDiffers).factories).toEqual([factory1]); - expect(childInjector.get(IterableDiffers).factories).toEqual([factory2, factory1]); + expect(injector.get(IterableDiffers).factories).toEqual([factory1]); + expect(childInjector.get(IterableDiffers).factories).toEqual([ + factory2, factory1 + ]); }); }); }); diff --git a/packages/core/test/di/static_injector_spec.ts b/packages/core/test/di/static_injector_spec.ts index f2b8df2f54..968a0847b8 100644 --- a/packages/core/test/di/static_injector_spec.ts +++ b/packages/core/test/di/static_injector_spec.ts @@ -98,7 +98,7 @@ export function main() { it('should resolve dependencies based on type information', () => { const injector = Injector.create([Engine.PROVIDER, Car.PROVIDER]); - const car = injector.get(Car); + const car = injector.get(Car); expect(car).toBeAnInstanceOf(Car); expect(car.engine).toBeAnInstanceOf(Engine); @@ -138,7 +138,7 @@ export function main() { const injector = Injector.create( [Engine.PROVIDER, {provide: Car, useFactory: sportsCarFactory, deps: [Engine]}]); - const car = injector.get(Car); + const car = injector.get(Car); expect(car).toBeAnInstanceOf(SportsCar); expect(car.engine).toBeAnInstanceOf(Engine); }); @@ -208,7 +208,7 @@ export function main() { {provide: Car, useFactory: (e: Engine) => new SportsCar(e), deps: [Engine]} ]); - const car = injector.get(Car); + const car = injector.get(Car); expect(car).toBeAnInstanceOf(SportsCar); expect(car.engine).toBeAnInstanceOf(Engine); }); @@ -216,7 +216,7 @@ export function main() { it('should support optional dependencies', () => { const injector = Injector.create([CarWithOptionalEngine.PROVIDER]); - const car = injector.get(CarWithOptionalEngine); + const car = injector.get(CarWithOptionalEngine); expect(car.engine).toEqual(null); }); @@ -288,7 +288,7 @@ export function main() { Injector.create([CarWithDashboard.PROVIDER, Engine.PROVIDER, Dashboard.PROVIDER]); expect(() => injector.get(CarWithDashboard)) .toThrowError( - `StaticInjectorError[${stringify(CarWithDashboard)} -> ${stringify(Dashboard)} -> DashboardSoftware]: + `StaticInjectorError[${stringify(CarWithDashboard)} -> ${stringify(Dashboard)} -> DashboardSoftware]: NullInjectorError: No provider for DashboardSoftware!`); }); @@ -364,7 +364,7 @@ export function main() { const parent = Injector.create([Car.PROVIDER, Engine.PROVIDER]); const child = Injector.create([TurboEngine.PROVIDER], parent); - const carFromChild = child.get(Car); + const carFromChild = child.get(Car); expect(carFromChild.engine).toBeAnInstanceOf(Engine); }); @@ -391,7 +391,7 @@ export function main() { it('should instantiate an object in the context of the injector', () => { const inj = Injector.create([Engine.PROVIDER]); const childInj = Injector.create([Car.PROVIDER], inj); - const car = childInj.get(Car); + const car = childInj.get(Car); expect(car).toBeAnInstanceOf(Car); expect(car.engine).toBe(inj.get(Engine)); }); @@ -415,7 +415,7 @@ export function main() { parent); expect(() => child.get(Car)) - .toThrowError(`StaticInjectorError[${stringify(Car)} -> ${stringify(Engine)}]: + .toThrowError(`StaticInjectorError[${stringify(Car)} -> ${stringify(Engine)}]: NullInjectorError: No provider for Engine!`); }); }); @@ -430,7 +430,7 @@ export function main() { ], parent); - expect(child.get(Car).engine).toBeAnInstanceOf(Engine); + expect(child.get(Car).engine).toBeAnInstanceOf(Engine); }); }); }); diff --git a/packages/core/test/linker/jit_summaries_integration_spec.ts b/packages/core/test/linker/jit_summaries_integration_spec.ts index dded12c530..8055e41847 100644 --- a/packages/core/test/linker/jit_summaries_integration_spec.ts +++ b/packages/core/test/linker/jit_summaries_integration_spec.ts @@ -232,7 +232,7 @@ export function main() { const fixture = TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []}) .configureTestingModule({providers: [SomeDep], imports: [SomeModule]}) - .createComponent(SomePublicComponent); + .createComponent(SomePublicComponent); expect(fixture.componentInstance.dep).toBe(overwrittenValue); }); diff --git a/packages/examples/upgrade/static/ts/module.ts b/packages/examples/upgrade/static/ts/module.ts index ce706a1748..27d5af51da 100644 --- a/packages/examples/upgrade/static/ts/module.ts +++ b/packages/examples/upgrade/static/ts/module.ts @@ -135,7 +135,7 @@ ng1AppModule.component('ng1Hero', { // This AngularJS service will be "upgraded" to be used in Angular ng1AppModule.factory( 'titleCase', - () => (value: string) => value.replace(/((^|\s)[a-z])/g, (_, c) => c.toUpperCase())); + (() => (value: string) => value.replace(/((^|\s)[a-z])/g, (_, c) => c.toUpperCase())) as any); // #enddocregion // #docregion downgrade-ng2-heroes-service @@ -154,18 +154,20 @@ ng1AppModule.component('exampleApp', { // We inject the "downgraded" HeroesService into this AngularJS component // (We don't need the `HeroesService` type for AngularJS DI - it just helps with TypeScript // compilation) - controller: [ - 'heroesService', function(heroesService: HeroesService) { this.heroesService = heroesService; } - ], - // This template make use of the downgraded `ng2-heroes` component - // Note that because its element is compiled by AngularJS we must use kebab-case attributes for - // inputs and outputs - template: ` + controller: + [ + 'heroesService', + function(heroesService: HeroesService) { this.heroesService = heroesService; } + ], + // This template make use of the downgraded `ng2-heroes` component + // Note that because its element is compiled by AngularJS we must use kebab-case attributes + // for inputs and outputs + template: `

Heroes

There are {{ $ctrl.heroesService.heroes.length }} heroes.

` -}); +} as any); // #enddocregion // #enddocregion diff --git a/packages/platform-server/test/integration_spec.ts b/packages/platform-server/test/integration_spec.ts index cfa7fd72c4..d4598c07e1 100644 --- a/packages/platform-server/test/integration_spec.ts +++ b/packages/platform-server/test/integration_spec.ts @@ -592,7 +592,7 @@ export function main() { platform.bootstrapModule(ExampleModule).then(ref => { const mock = ref.injector.get(MockBackend); const http = ref.injector.get(Http); - ref.injector.get(NgZone).run(() => { + ref.injector.get(NgZone).run(() => { NgZone.assertInAngularZone(); mock.connections.subscribe((mc: MockConnection) => { NgZone.assertInAngularZone(); @@ -612,11 +612,11 @@ export function main() { platform.bootstrapModule(ExampleModule).then(ref => { const mock = ref.injector.get(MockBackend); const http = ref.injector.get(Http); - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); - ref.injector.get(NgZone).run(() => { + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); + ref.injector.get(NgZone).run(() => { NgZone.assertInAngularZone(); mock.connections.subscribe((mc: MockConnection) => { - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); mc.mockRespond(new Response(new ResponseOptions({body: 'success!', status: 200}))); }); http.get('http://localhost/testing').subscribe(resp => { @@ -631,11 +631,11 @@ export function main() { platform.bootstrapModule(HttpBeforeExampleModule).then(ref => { const mock = ref.injector.get(MockBackend); const http = ref.injector.get(Http); - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); - ref.injector.get(NgZone).run(() => { + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); + ref.injector.get(NgZone).run(() => { NgZone.assertInAngularZone(); mock.connections.subscribe((mc: MockConnection) => { - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); mc.mockRespond(new Response(new ResponseOptions({body: 'success!', status: 200}))); }); http.get('http://localhost/testing').subscribe(resp => { @@ -650,11 +650,11 @@ export function main() { platform.bootstrapModule(HttpAfterExampleModule).then(ref => { const mock = ref.injector.get(MockBackend); const http = ref.injector.get(Http); - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); - ref.injector.get(NgZone).run(() => { + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); + ref.injector.get(NgZone).run(() => { NgZone.assertInAngularZone(); mock.connections.subscribe((mc: MockConnection) => { - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); mc.mockRespond(new Response(new ResponseOptions({body: 'success!', status: 200}))); }); http.get('http://localhost/testing').subscribe(resp => { @@ -688,7 +688,7 @@ export function main() { platform.bootstrapModule(HttpClientExmapleModule).then(ref => { const mock = ref.injector.get(HttpTestingController) as HttpTestingController; const http = ref.injector.get(HttpClient); - ref.injector.get(NgZone).run(() => { + ref.injector.get(NgZone).run(() => { http.get('http://localhost/testing').subscribe(body => { NgZone.assertInAngularZone(); expect(body).toEqual('success!'); @@ -703,13 +703,13 @@ export function main() { platform.bootstrapModule(HttpClientExmapleModule).then(ref => { const mock = ref.injector.get(HttpTestingController) as HttpTestingController; const http = ref.injector.get(HttpClient); - ref.injector.get(NgZone).run(() => { + ref.injector.get(NgZone).run(() => { http.get('http://localhost/testing').subscribe(body => { expect(body).toEqual('success!'); }); - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy(); mock.expectOne('http://localhost/testing').flush('success!'); - expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); + expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy(); }); }); })); diff --git a/packages/platform-webworker/src/web_workers/ui/location_providers.ts b/packages/platform-webworker/src/web_workers/ui/location_providers.ts index f399cba7a8..56b6790e56 100644 --- a/packages/platform-webworker/src/web_workers/ui/location_providers.ts +++ b/packages/platform-webworker/src/web_workers/ui/location_providers.ts @@ -32,7 +32,7 @@ export const WORKER_UI_LOCATION_PROVIDERS = [ function initUiLocation(injector: Injector): () => void { return () => { - const zone = injector.get(NgZone); + const zone = injector.get(NgZone); zone.runGuarded(() => injector.get(MessageBasedPlatformLocation).start()); }; diff --git a/packages/platform-webworker/src/worker_render.ts b/packages/platform-webworker/src/worker_render.ts index f0ed0580c2..889ca3359a 100644 --- a/packages/platform-webworker/src/worker_render.ts +++ b/packages/platform-webworker/src/worker_render.ts @@ -112,7 +112,7 @@ export const _WORKER_UI_PLATFORM_PROVIDERS: StaticProvider[] = [ function initializeGenericWorkerRenderer(injector: Injector) { const bus = injector.get(MessageBus); - const zone = injector.get(NgZone); + const zone = injector.get(NgZone); bus.attachToZone(zone); // initialize message services after the bus has been created diff --git a/packages/router/src/router_module.ts b/packages/router/src/router_module.ts index 91d038c517..fcfb4c8c27 100644 --- a/packages/router/src/router_module.ts +++ b/packages/router/src/router_module.ts @@ -381,7 +381,7 @@ export class RouterInitializer { const opts = this.injector.get(ROUTER_CONFIGURATION); const preloader = this.injector.get(RouterPreloader); const router = this.injector.get(Router); - const ref = this.injector.get(ApplicationRef); + const ref = this.injector.get(ApplicationRef); if (bootstrappedComponentRef !== ref.components[0]) { return; diff --git a/packages/upgrade/src/dynamic/upgrade_adapter.ts b/packages/upgrade/src/dynamic/upgrade_adapter.ts index c4d3e44b18..00c52dff49 100644 --- a/packages/upgrade/src/dynamic/upgrade_adapter.ts +++ b/packages/upgrade/src/dynamic/upgrade_adapter.ts @@ -399,7 +399,7 @@ export class UpgradeAdapter { Promise.all([this.ng2BootstrapDeferred.promise, ng1BootstrapPromise]).then(([ng1Injector]) => { angular.element(element).data !(controllerKey(INJECTOR_KEY), this.moduleRef !.injector); - this.moduleRef !.injector.get(NgZone).run( + this.moduleRef !.injector.get(NgZone).run( () => { (upgrade)._bootstrapDone(this.moduleRef, ng1Injector); }); }, onError); return upgrade; diff --git a/packages/upgrade/src/dynamic/upgrade_ng1_adapter.ts b/packages/upgrade/src/dynamic/upgrade_ng1_adapter.ts index 5acc8f7de1..3aedd1c3d1 100644 --- a/packages/upgrade/src/dynamic/upgrade_ng1_adapter.ts +++ b/packages/upgrade/src/dynamic/upgrade_ng1_adapter.ts @@ -67,7 +67,7 @@ export class UpgradeNg1ComponentAdapterBuilder { extractBindings() { const btcIsObject = typeof this.directive !.bindToController === 'object'; - if (btcIsObject && Object.keys(this.directive !.scope).length) { + if (btcIsObject && Object.keys(this.directive !.scope !).length) { throw new Error( `Binding definitions on scope and controller at the same time are not supported.`); } diff --git a/packages/upgrade/src/static/upgrade_component.ts b/packages/upgrade/src/static/upgrade_component.ts index 06908f7595..5a670b15ff 100644 --- a/packages/upgrade/src/static/upgrade_component.ts +++ b/packages/upgrade/src/static/upgrade_component.ts @@ -227,7 +227,7 @@ export class UpgradeComponent implements OnInit, OnChanges, DoCheck, OnDestroy { private initializeBindings(directive: angular.IDirective) { const btcIsObject = typeof directive.bindToController === 'object'; - if (btcIsObject && Object.keys(directive.scope).length) { + if (btcIsObject && Object.keys(directive.scope !).length) { throw new Error( `Binding definitions on scope and controller at the same time is not supported.`); } diff --git a/tools/public_api_guard/platform-webworker/platform-webworker.d.ts b/tools/public_api_guard/platform-webworker/platform-webworker.d.ts index 3c1ab1472f..15c158de9a 100644 --- a/tools/public_api_guard/platform-webworker/platform-webworker.d.ts +++ b/tools/public_api_guard/platform-webworker/platform-webworker.d.ts @@ -93,7 +93,7 @@ export declare const WORKER_APP_LOCATION_PROVIDERS: ({ } | { provide: InjectionToken>; useFactory: (platformLocation: WebWorkerPlatformLocation) => Promise; - deps: typeof PlatformLocation[]; + deps: (typeof PlatformLocation)[]; })[]; /** @experimental */