From 3c7359f02625996ebec5a5fa4bda34af4a770f26 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 30 Jul 2020 13:03:15 +0300 Subject: [PATCH] refactor(docs-infra): fix docs examples for tslint rule `no-angle-bracket-type-assertion` (#38143) This commit updates the docs examples to be compatible with the `no-angle-bracket-type-assertion` tslint rule. This is in preparation of updating the docs examples `tslint.json` to match the one generated for new Angular CLI apps in a future commit. PR Close #38143 --- aio/content/examples/binding-syntax/src/app/app.component.ts | 2 +- .../dynamic-component-loader/src/app/ad-banner.component.ts | 4 ++-- aio/content/examples/event-binding/src/app/app.component.ts | 4 ++-- .../styleguide/src/04-11/app/core/spinner/spinner.service.ts | 4 ++-- .../examples/testing/src/app/demo/demo.testbed.spec.ts | 4 ++-- .../src/app/hero/hero-detail.component.no-testbed.spec.ts | 2 +- .../testing/src/app/hero/hero-detail.component.spec.ts | 2 +- .../examples/testing/src/app/model/hero.service.spec.ts | 2 +- aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/aio/content/examples/binding-syntax/src/app/app.component.ts b/aio/content/examples/binding-syntax/src/app/app.component.ts index bed9bd2a75..525f175d66 100644 --- a/aio/content/examples/binding-syntax/src/app/app.component.ts +++ b/aio/content/examples/binding-syntax/src/app/app.component.ts @@ -26,7 +26,7 @@ export class AppComponent { toggleDisabled(): any { - let testButton = document.getElementById('testButton'); + let testButton = document.getElementById('testButton') as HTMLInputElement; testButton.disabled = !testButton.disabled; console.warn(testButton.disabled); } diff --git a/aio/content/examples/dynamic-component-loader/src/app/ad-banner.component.ts b/aio/content/examples/dynamic-component-loader/src/app/ad-banner.component.ts index 2fe5597f95..7e686be87a 100644 --- a/aio/content/examples/dynamic-component-loader/src/app/ad-banner.component.ts +++ b/aio/content/examples/dynamic-component-loader/src/app/ad-banner.component.ts @@ -43,8 +43,8 @@ export class AdBannerComponent implements OnInit, OnDestroy { const viewContainerRef = this.adHost.viewContainerRef; viewContainerRef.clear(); - const componentRef = viewContainerRef.createComponent(componentFactory); - (componentRef.instance).data = adItem.data; + const componentRef = viewContainerRef.createComponent(componentFactory); + componentRef.instance.data = adItem.data; } getAds() { diff --git a/aio/content/examples/event-binding/src/app/app.component.ts b/aio/content/examples/event-binding/src/app/app.component.ts index e8e7882d89..02a1328f17 100644 --- a/aio/content/examples/event-binding/src/app/app.component.ts +++ b/aio/content/examples/event-binding/src/app/app.component.ts @@ -12,7 +12,7 @@ export class AppComponent { clickMessage = ''; onSave(event?: KeyboardEvent) { - const evtMsg = event ? ' Event target is ' + (event.target).textContent : ''; + const evtMsg = event ? ' Event target is ' + (event.target as HTMLElement).textContent : ''; alert('Saved.' + evtMsg); if (event) { event.stopPropagation(); } } @@ -22,7 +22,7 @@ export class AppComponent { } onClickMe(event?: KeyboardEvent) { - const evtMsg = event ? ' Event target class is ' + (event.target).className : ''; + const evtMsg = event ? ' Event target class is ' + (event.target as HTMLElement).className : ''; alert('Click me.' + evtMsg); } diff --git a/aio/content/examples/styleguide/src/04-11/app/core/spinner/spinner.service.ts b/aio/content/examples/styleguide/src/04-11/app/core/spinner/spinner.service.ts index e092d4bfda..67881864a7 100644 --- a/aio/content/examples/styleguide/src/04-11/app/core/spinner/spinner.service.ts +++ b/aio/content/examples/styleguide/src/04-11/app/core/spinner/spinner.service.ts @@ -15,10 +15,10 @@ export class SpinnerService { constructor() { } show() { - this.spinnerSubject.next({ show: true }); + this.spinnerSubject.next({ show: true }); } hide() { - this.spinnerSubject.next({ show: false }); + this.spinnerSubject.next({ show: false }); } } diff --git a/aio/content/examples/testing/src/app/demo/demo.testbed.spec.ts b/aio/content/examples/testing/src/app/demo/demo.testbed.spec.ts index 1b97cc572f..cb5b20ea6a 100644 --- a/aio/content/examples/testing/src/app/demo/demo.testbed.spec.ts +++ b/aio/content/examples/testing/src/app/demo/demo.testbed.spec.ts @@ -256,7 +256,7 @@ describe('demo (with TestBed):', () => { fixture.detectChanges(); const comp = fixture.componentInstance; - const input = fixture.debugElement.query(By.css('input')).nativeElement; + const input = fixture.debugElement.query(By.css('input')).nativeElement as HTMLInputElement; expect(comp.name).toBe(expectedOrigName, `At start name should be ${expectedOrigName} `); @@ -294,7 +294,7 @@ describe('demo (with TestBed):', () => { fixture.detectChanges(); const comp = fixture.componentInstance; - const input = fixture.debugElement.query(By.css('input')).nativeElement; + const input = fixture.debugElement.query(By.css('input')).nativeElement as HTMLInputElement; expect(comp.name).toBe(expectedOrigName, `At start name should be ${expectedOrigName} `); diff --git a/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts b/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts index 3eb5835272..51e65e65bb 100644 --- a/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts +++ b/aio/content/examples/testing/src/app/hero/hero-detail.component.no-testbed.spec.ts @@ -21,7 +21,7 @@ describe('HeroDetailComponent - no TestBed', () => { hds.getHero.and.returnValue(asyncData(expectedHero)); hds.saveHero.and.returnValue(asyncData(expectedHero)); - comp = new HeroDetailComponent(hds, activatedRoute, router); + comp = new HeroDetailComponent(hds, activatedRoute as any, router); comp.ngOnInit(); // OnInit calls HDS.getHero; wait for it to get the fake hero diff --git a/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts b/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts index fb949019ff..0d0c4af9e9 100644 --- a/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts +++ b/aio/content/examples/testing/src/app/hero/hero-detail.component.spec.ts @@ -358,7 +358,7 @@ class Page { constructor(fixture: ComponentFixture) { // get the navigate spy from the injected router spy object - const routerSpy = fixture.debugElement.injector.get(Router); + const routerSpy = someFixture.debugElement.injector.get(Router) as any; this.navigateSpy = routerSpy.navigate; // spy on component's `gotoList()` method diff --git a/aio/content/examples/testing/src/app/model/hero.service.spec.ts b/aio/content/examples/testing/src/app/model/hero.service.spec.ts index 2c77ff3c10..c2e57e6d76 100644 --- a/aio/content/examples/testing/src/app/model/hero.service.spec.ts +++ b/aio/content/examples/testing/src/app/model/hero.service.spec.ts @@ -17,7 +17,7 @@ describe ('HeroesService (with spies)', () => { beforeEach(() => { // TODO: spy on other methods too httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']); - heroService = new HeroService( httpClientSpy); + heroService = new HeroService(httpClientSpy as any); }); it('should return expected heroes (HttpClient called once)', () => { diff --git a/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts b/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts index b3d72f8f3e..2f8b82a13b 100644 --- a/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts +++ b/aio/content/examples/toh-pt6/e2e/src/app.e2e-spec.ts @@ -301,5 +301,5 @@ function getHeroLiEltById(id: number): ElementFinder { async function toHeroArray(allHeroes: ElementArrayFinder): Promise { let promisedHeroes = await allHeroes.map(Hero.fromLi); // The cast is necessary to get around issuing with the signature of Promise.all() - return > Promise.all(promisedHeroes); + return Promise.all(promisedHeroes) as Promise; }