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
This commit is contained in:
George Kalpakas 2020-07-30 13:03:15 +03:00 committed by Alex Rickabaugh
parent 8aa29438ac
commit 3c7359f026
9 changed files with 13 additions and 13 deletions

View File

@ -26,7 +26,7 @@ export class AppComponent {
toggleDisabled(): any { toggleDisabled(): any {
let testButton = <HTMLInputElement> document.getElementById('testButton'); let testButton = document.getElementById('testButton') as HTMLInputElement;
testButton.disabled = !testButton.disabled; testButton.disabled = !testButton.disabled;
console.warn(testButton.disabled); console.warn(testButton.disabled);
} }

View File

@ -43,8 +43,8 @@ export class AdBannerComponent implements OnInit, OnDestroy {
const viewContainerRef = this.adHost.viewContainerRef; const viewContainerRef = this.adHost.viewContainerRef;
viewContainerRef.clear(); viewContainerRef.clear();
const componentRef = viewContainerRef.createComponent(componentFactory); const componentRef = viewContainerRef.createComponent<AdComponent>(componentFactory);
(<AdComponent>componentRef.instance).data = adItem.data; componentRef.instance.data = adItem.data;
} }
getAds() { getAds() {

View File

@ -12,7 +12,7 @@ export class AppComponent {
clickMessage = ''; clickMessage = '';
onSave(event?: KeyboardEvent) { onSave(event?: KeyboardEvent) {
const evtMsg = event ? ' Event target is ' + (<HTMLElement>event.target).textContent : ''; const evtMsg = event ? ' Event target is ' + (event.target as HTMLElement).textContent : '';
alert('Saved.' + evtMsg); alert('Saved.' + evtMsg);
if (event) { event.stopPropagation(); } if (event) { event.stopPropagation(); }
} }
@ -22,7 +22,7 @@ export class AppComponent {
} }
onClickMe(event?: KeyboardEvent) { onClickMe(event?: KeyboardEvent) {
const evtMsg = event ? ' Event target class is ' + (<HTMLElement>event.target).className : ''; const evtMsg = event ? ' Event target class is ' + (event.target as HTMLElement).className : '';
alert('Click me.' + evtMsg); alert('Click me.' + evtMsg);
} }

View File

@ -15,10 +15,10 @@ export class SpinnerService {
constructor() { } constructor() { }
show() { show() {
this.spinnerSubject.next(<SpinnerState>{ show: true }); this.spinnerSubject.next({ show: true });
} }
hide() { hide() {
this.spinnerSubject.next(<SpinnerState>{ show: false }); this.spinnerSubject.next({ show: false });
} }
} }

View File

@ -256,7 +256,7 @@ describe('demo (with TestBed):', () => {
fixture.detectChanges(); fixture.detectChanges();
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
const input = <HTMLInputElement> fixture.debugElement.query(By.css('input')).nativeElement; const input = fixture.debugElement.query(By.css('input')).nativeElement as HTMLInputElement;
expect(comp.name).toBe(expectedOrigName, expect(comp.name).toBe(expectedOrigName,
`At start name should be ${expectedOrigName} `); `At start name should be ${expectedOrigName} `);
@ -294,7 +294,7 @@ describe('demo (with TestBed):', () => {
fixture.detectChanges(); fixture.detectChanges();
const comp = fixture.componentInstance; const comp = fixture.componentInstance;
const input = <HTMLInputElement> fixture.debugElement.query(By.css('input')).nativeElement; const input = fixture.debugElement.query(By.css('input')).nativeElement as HTMLInputElement;
expect(comp.name).toBe(expectedOrigName, expect(comp.name).toBe(expectedOrigName,
`At start name should be ${expectedOrigName} `); `At start name should be ${expectedOrigName} `);

View File

@ -21,7 +21,7 @@ describe('HeroDetailComponent - no TestBed', () => {
hds.getHero.and.returnValue(asyncData(expectedHero)); hds.getHero.and.returnValue(asyncData(expectedHero));
hds.saveHero.and.returnValue(asyncData(expectedHero)); hds.saveHero.and.returnValue(asyncData(expectedHero));
comp = new HeroDetailComponent(hds, <any> activatedRoute, router); comp = new HeroDetailComponent(hds, activatedRoute as any, router);
comp.ngOnInit(); comp.ngOnInit();
// OnInit calls HDS.getHero; wait for it to get the fake hero // OnInit calls HDS.getHero; wait for it to get the fake hero

View File

@ -358,7 +358,7 @@ class Page {
constructor(fixture: ComponentFixture<HeroDetailComponent>) { constructor(fixture: ComponentFixture<HeroDetailComponent>) {
// get the navigate spy from the injected router spy object // get the navigate spy from the injected router spy object
const routerSpy = <any> fixture.debugElement.injector.get(Router); const routerSpy = someFixture.debugElement.injector.get(Router) as any;
this.navigateSpy = routerSpy.navigate; this.navigateSpy = routerSpy.navigate;
// spy on component's `gotoList()` method // spy on component's `gotoList()` method

View File

@ -17,7 +17,7 @@ describe ('HeroesService (with spies)', () => {
beforeEach(() => { beforeEach(() => {
// TODO: spy on other methods too // TODO: spy on other methods too
httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']); httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']);
heroService = new HeroService(<any> httpClientSpy); heroService = new HeroService(httpClientSpy as any);
}); });
it('should return expected heroes (HttpClient called once)', () => { it('should return expected heroes (HttpClient called once)', () => {

View File

@ -301,5 +301,5 @@ function getHeroLiEltById(id: number): ElementFinder {
async function toHeroArray(allHeroes: ElementArrayFinder): Promise<Hero[]> { async function toHeroArray(allHeroes: ElementArrayFinder): Promise<Hero[]> {
let promisedHeroes = await allHeroes.map(Hero.fromLi); let promisedHeroes = await allHeroes.map(Hero.fromLi);
// The cast is necessary to get around issuing with the signature of Promise.all() // The cast is necessary to get around issuing with the signature of Promise.all()
return <Promise<any>> Promise.all(promisedHeroes); return Promise.all(promisedHeroes) as Promise<any>;
} }