fix: Update test code to type-check under TS 2.5 (#20175)
PR Close #20175
This commit is contained in:
parent
c2a24b4241
commit
5ec1717c58
|
@ -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")
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -17,7 +17,7 @@ export function main() {
|
|||
ids.map(id => ({provide: id, useValue: new MockMetric(id)})),
|
||||
MultiMetric.provideWith(ids)
|
||||
])
|
||||
.get(MultiMetric);
|
||||
.get<MultiMetric>(MultiMetric);
|
||||
return Promise.resolve(m);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ export function main() {
|
|||
}
|
||||
}
|
||||
];
|
||||
return Injector.create(providers).get(JsonFileReporter);
|
||||
return Injector.create(providers).get<JsonFileReporter>(JsonFileReporter);
|
||||
}
|
||||
|
||||
it('should write all data into a file',
|
||||
|
|
|
@ -17,7 +17,7 @@ export function main() {
|
|||
ids.map(id => ({provide: id, useValue: new MockReporter(id)})),
|
||||
MultiReporter.provideWith(ids)
|
||||
])
|
||||
.get(MultiReporter);
|
||||
.get<MultiReporter>(MultiReporter);
|
||||
return Promise.resolve(r);
|
||||
}
|
||||
|
||||
|
|
|
@ -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([
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>(IterableDiffers).factories).toEqual([factory1]);
|
||||
expect(childInjector.get<IterableDiffers>(IterableDiffers).factories).toEqual([
|
||||
factory2, factory1
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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>(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>(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>(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>(CarWithOptionalEngine);
|
||||
expect(car.engine).toEqual(null);
|
||||
});
|
||||
|
||||
|
@ -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>(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>(Car);
|
||||
expect(car).toBeAnInstanceOf(Car);
|
||||
expect(car.engine).toBe(inj.get(Engine));
|
||||
});
|
||||
|
@ -430,7 +430,7 @@ export function main() {
|
|||
],
|
||||
parent);
|
||||
|
||||
expect(child.get(Car).engine).toBeAnInstanceOf(Engine);
|
||||
expect(child.get<Car>(Car).engine).toBeAnInstanceOf(Engine);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -232,7 +232,7 @@ export function main() {
|
|||
const fixture =
|
||||
TestBed.overrideProvider(SomeDep, {useFactory: () => overwrittenValue, deps: []})
|
||||
.configureTestingModule({providers: [SomeDep], imports: [SomeModule]})
|
||||
.createComponent(SomePublicComponent);
|
||||
.createComponent<SomePublicComponent>(SomePublicComponent);
|
||||
|
||||
expect(fixture.componentInstance.dep).toBe(overwrittenValue);
|
||||
});
|
||||
|
|
|
@ -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; }
|
||||
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
|
||||
// Note that because its element is compiled by AngularJS we must use kebab-case attributes
|
||||
// for inputs and outputs
|
||||
template: `<link rel="stylesheet" href="./styles.css">
|
||||
<ng2-heroes [heroes]="$ctrl.heroesService.heroes" (add-hero)="$ctrl.heroesService.addHero()" (remove-hero)="$ctrl.heroesService.removeHero($event)">
|
||||
<h1>Heroes</h1>
|
||||
<p class="extra">There are {{ $ctrl.heroesService.heroes.length }} heroes.</p>
|
||||
</ng2-heroes>`
|
||||
});
|
||||
} as any);
|
||||
// #enddocregion
|
||||
// #enddocregion
|
||||
|
||||
|
|
|
@ -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>(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>(NgZone).hasPendingMacrotasks).toBeFalsy();
|
||||
ref.injector.get<NgZone>(NgZone).run(() => {
|
||||
NgZone.assertInAngularZone();
|
||||
mock.connections.subscribe((mc: MockConnection) => {
|
||||
expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||
expect(ref.injector.get<NgZone>(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>(NgZone).hasPendingMacrotasks).toBeFalsy();
|
||||
ref.injector.get<NgZone>(NgZone).run(() => {
|
||||
NgZone.assertInAngularZone();
|
||||
mock.connections.subscribe((mc: MockConnection) => {
|
||||
expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||
expect(ref.injector.get<NgZone>(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>(NgZone).hasPendingMacrotasks).toBeFalsy();
|
||||
ref.injector.get<NgZone>(NgZone).run(() => {
|
||||
NgZone.assertInAngularZone();
|
||||
mock.connections.subscribe((mc: MockConnection) => {
|
||||
expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||
expect(ref.injector.get<NgZone>(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>(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>(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>(NgZone).hasPendingMacrotasks).toBeTruthy();
|
||||
mock.expectOne('http://localhost/testing').flush('success!');
|
||||
expect(ref.injector.get(NgZone).hasPendingMacrotasks).toBeFalsy();
|
||||
expect(ref.injector.get<NgZone>(NgZone).hasPendingMacrotasks).toBeFalsy();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
|
|
@ -32,7 +32,7 @@ export const WORKER_UI_LOCATION_PROVIDERS = <StaticProvider[]>[
|
|||
|
||||
function initUiLocation(injector: Injector): () => void {
|
||||
return () => {
|
||||
const zone = injector.get(NgZone);
|
||||
const zone = injector.get<NgZone>(NgZone);
|
||||
|
||||
zone.runGuarded(() => injector.get(MessageBasedPlatformLocation).start());
|
||||
};
|
||||
|
|
|
@ -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>(NgZone);
|
||||
bus.attachToZone(zone);
|
||||
|
||||
// initialize message services after the bus has been created
|
||||
|
|
|
@ -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>(ApplicationRef);
|
||||
|
||||
if (bootstrappedComponentRef !== ref.components[0]) {
|
||||
return;
|
||||
|
|
|
@ -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>(NgZone).run(
|
||||
() => { (<any>upgrade)._bootstrapDone(this.moduleRef, ng1Injector); });
|
||||
}, onError);
|
||||
return upgrade;
|
||||
|
|
|
@ -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.`);
|
||||
}
|
||||
|
|
|
@ -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.`);
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ export declare const WORKER_APP_LOCATION_PROVIDERS: ({
|
|||
} | {
|
||||
provide: InjectionToken<Promise<any>>;
|
||||
useFactory: (platformLocation: WebWorkerPlatformLocation) => Promise<any>;
|
||||
deps: typeof PlatformLocation[];
|
||||
deps: (typeof PlatformLocation)[];
|
||||
})[];
|
||||
|
||||
/** @experimental */
|
||||
|
|
Loading…
Reference in New Issue