Skip to content

Commit c5c6d84

Browse files
petebacondarwinalexeagle
authored andcommitted
style(aio): enforce strict TypeScript checks (angular#21342)
Closes angular#20646 PR Close angular#21342
1 parent 246de65 commit c5c6d84

File tree

57 files changed

+198
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+198
-194
lines changed

aio/content/examples/service-worker-getting-started/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"@angular/core": "^5.0.0",
1919
"@angular/forms": "^5.0.0",
2020
"@angular/http": "^5.0.0",
21-
"@angular/service-worker": "^5.0.0",
2221
"@angular/platform-browser": "^5.0.0",
2322
"@angular/platform-browser-dynamic": "^5.0.0",
2423
"@angular/router": "^5.0.0",

aio/e2e/api.po.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class ApiPage extends SitePage {
2525
// and we want to be able to pull out the code elements from only the first level
2626
// if `onlyDirect` is set to `true`.
2727
const selector = `.descendants.${docType} ${onlyDirect ? '>' : ''} li > :not(ul) code`;
28-
return element.all(by.css(selector)).map<string>(item => item.getText());
28+
return element.all(by.css(selector)).map<string>(item => item && item.getText());
2929
}
3030

3131
getOverview(docType) {

aio/e2e/app.po.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ export class SitePage {
6262
getSearchResults() {
6363
const results = element.all(by.css('.search-results li'));
6464
browser.wait(ExpectedConditions.presenceOf(results.first()), 8000);
65-
return results.map(link => link.getText());
65+
return results.map(link => link && link.getText());
6666
}
6767
}

aio/src/app/app.component.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ describe('AppComponent', () => {
314314
it('should not navigate when change to a version without a url', () => {
315315
setupSelectorForTesting();
316316
const versionWithoutUrlIndex = component.docVersions.length;
317-
const versionWithoutUrl = component.docVersions[versionWithoutUrlIndex] = { title: 'foo', url: null };
317+
const versionWithoutUrl = component.docVersions[versionWithoutUrlIndex] = { title: 'foo' };
318318
selectElement.triggerEventHandler('change', { option: versionWithoutUrl, index: versionWithoutUrlIndex });
319319
expect(locationService.go).not.toHaveBeenCalled();
320320
});
@@ -520,9 +520,9 @@ describe('AppComponent', () => {
520520

521521
describe('aio-toc', () => {
522522
let tocDebugElement: DebugElement;
523-
let tocContainer: DebugElement;
523+
let tocContainer: DebugElement|null;
524524

525-
const setHasFloatingToc = hasFloatingToc => {
525+
const setHasFloatingToc = (hasFloatingToc: boolean) => {
526526
component.hasFloatingToc = hasFloatingToc;
527527
fixture.detectChanges();
528528

@@ -551,12 +551,12 @@ describe('AppComponent', () => {
551551
});
552552

553553
it('should update the TOC container\'s `maxHeight` based on `tocMaxHeight`', () => {
554-
expect(tocContainer.styles['max-height']).toBeNull();
554+
expect(tocContainer!.styles['max-height']).toBeNull();
555555

556556
component.tocMaxHeight = '100';
557557
fixture.detectChanges();
558558

559-
expect(tocContainer.styles['max-height']).toBe('100px');
559+
expect(tocContainer!.styles['max-height']).toBe('100px');
560560
});
561561

562562
it('should restrain scrolling inside the ToC container', () => {
@@ -565,7 +565,7 @@ describe('AppComponent', () => {
565565

566566
expect(restrainScrolling).not.toHaveBeenCalled();
567567

568-
tocContainer.triggerEventHandler('mousewheel', evt);
568+
tocContainer!.triggerEventHandler('mousewheel', evt);
569569
expect(restrainScrolling).toHaveBeenCalledWith(evt);
570570
});
571571
});
@@ -591,7 +591,7 @@ describe('AppComponent', () => {
591591
initializeTest();
592592
fixture.detectChanges();
593593
const banner: HTMLElement = fixture.debugElement.query(By.css('aio-mode-banner')).nativeElement;
594-
expect(banner.textContent.trim()).toEqual('');
594+
expect(banner.textContent!.trim()).toEqual('');
595595
});
596596
});
597597

@@ -985,9 +985,9 @@ describe('AppComponent', () => {
985985
checkHostClass('mode', 'archive');
986986
});
987987

988-
function checkHostClass(type, value) {
988+
function checkHostClass(type: string, value: string) {
989989
const host = fixture.debugElement;
990-
const classes = host.properties['className'];
990+
const classes: string = host.properties['className'];
991991
const classArray = classes.split(' ').filter(c => c.indexOf(`${type}-`) === 0);
992992
expect(classArray.length).toBeLessThanOrEqual(1, `"${classes}" should have only one class matching ${type}-*`);
993993
expect(classArray).toEqual([`${type}-${value}`], `"${classes}" should contain ${type}-${value}`);
@@ -1212,10 +1212,10 @@ class TestHttpClient {
12121212
if (/navigation\.json/.test(url)) {
12131213
data = this.navJson;
12141214
} else {
1215-
const match = /generated\/docs\/(.+)\.json/.exec(url);
1216-
const id = match[1];
1215+
const match = /generated\/docs\/(.+)\.json/.exec(url)!;
1216+
const id = match[1]!;
12171217
// Make up a title for test purposes
1218-
const title = id.split('/').pop().replace(/^([a-z])/, (_, letter) => letter.toUpperCase());
1218+
const title = id.split('/').pop()!.replace(/^([a-z])/, (_, letter) => letter.toUpperCase());
12191219
const h1 = (id === 'no-title') ? '' : `<h1>${title}</h1>`;
12201220
const contents = `${h1}<h2 id="#somewhere">Some heading</h2>`;
12211221
data = { id, contents };

aio/src/app/app.component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,19 @@ export class AppComponent implements OnInit {
152152
this.navigationService.navigationViews.map(views => views['docVersions']))
153153
.subscribe(([versionInfo, versions]) => {
154154
// TODO(pbd): consider whether we can lookup the stable and next versions from the internet
155-
const computedVersions = [
155+
const computedVersions: NavigationNode[] = [
156156
{ title: 'next', url: 'https://next.angular.io' },
157157
{ title: 'stable', url: 'https://angular.io' },
158158
];
159159
if (this.deployment.mode === 'archive') {
160-
computedVersions.push({ title: `v${versionInfo.major}`, url: null });
160+
computedVersions.push({ title: `v${versionInfo.major}` });
161161
}
162162
this.docVersions = [...computedVersions, ...versions];
163163

164164
// Find the current version - eithers title matches the current deployment mode
165165
// or its title matches the major version of the current version info
166166
this.currentDocVersion = this.docVersions.find(version =>
167-
version.title === this.deployment.mode || version.title === `v${versionInfo.major}`);
167+
version.title === this.deployment.mode || version.title === `v${versionInfo.major}`)!;
168168
this.currentDocVersion.title += ` (v${versionInfo.raw})`;
169169
});
170170

@@ -232,7 +232,7 @@ export class AppComponent implements OnInit {
232232
}
233233

234234
@HostListener('window:resize', ['$event.target.innerWidth'])
235-
onResize(width) {
235+
onResize(width: number) {
236236
this.isSideBySide = width > this.sideBySideWidth;
237237
this.showFloatingToc.next(width > this.showFloatingTocWidth);
238238
}
@@ -252,7 +252,7 @@ export class AppComponent implements OnInit {
252252
}
253253

254254
// Deal with anchor clicks; climb DOM tree until anchor found (or null)
255-
let target = eventTarget;
255+
let target: HTMLElement|null = eventTarget;
256256
while (target && !(target instanceof HTMLAnchorElement)) {
257257
target = target.parentElement;
258258
}
@@ -335,8 +335,8 @@ export class AppComponent implements OnInit {
335335
// Must wait until now for mat-toolbar to be measurable.
336336
const el = this.hostElement.nativeElement as Element;
337337
this.tocMaxHeightOffset =
338-
el.querySelector('footer').clientHeight +
339-
el.querySelector('.app-toolbar').clientHeight +
338+
el.querySelector('footer')!.clientHeight +
339+
el.querySelector('.app-toolbar')!.clientHeight +
340340
24; // fudge margin
341341
}
342342

@@ -375,7 +375,7 @@ export class AppComponent implements OnInit {
375375
}
376376
}
377377

378-
doSearch(query) {
378+
doSearch(query: string) {
379379
this.searchResults = this.searchService.search(query);
380380
this.showSearchResults = !!query;
381381
}

aio/src/app/app.module.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('AppModule', () => {
2323
});
2424

2525
it('should provide a list of eagerly-loaded embedded components', () => {
26-
const eagerSelector = Object.keys(componentsMap).find(selector => Array.isArray(componentsMap[selector]));
26+
const eagerSelector = Object.keys(componentsMap).find(selector => Array.isArray(componentsMap[selector]))!;
2727
const selectorCount = eagerSelector.split(',').length;
2828

2929
expect(eagerSelector).not.toBeNull();
@@ -34,7 +34,7 @@ describe('AppModule', () => {
3434
});
3535

3636
it('should provide a list of lazy-loaded embedded components', () => {
37-
const lazySelector = Object.keys(componentsMap).find(selector => selector.includes('code-example'));
37+
const lazySelector = Object.keys(componentsMap).find(selector => selector.includes('code-example'))!;
3838
const selectorCount = lazySelector.split(',').length;
3939

4040
expect(lazySelector).not.toBeNull();

aio/src/app/documents/document-contents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export interface DocumentContents {
22
/** The unique identifier for this document */
33
id: string;
44
/** The HTML to display in the doc viewer */
5-
contents: string;
5+
contents: string|null;
66
}

aio/src/app/documents/document.service.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('DocumentService', () => {
5050
});
5151

5252
it('should emit a document each time the location changes', () => {
53-
let latestDocument: DocumentContents;
53+
let latestDocument: DocumentContents|undefined;
5454
const doc0 = { contents: 'doc 0', id: 'initial/doc' };
5555
const doc1 = { contents: 'doc 1', id: 'new/doc' };
5656
const { docService, locationService } = getServices('initial/doc');
@@ -67,7 +67,7 @@ describe('DocumentService', () => {
6767
});
6868

6969
it('should emit the not-found document if the document is not found on the server', () => {
70-
let currentDocument: DocumentContents;
70+
let currentDocument: DocumentContents|undefined;
7171
const notFoundDoc = { id: FILE_NOT_FOUND_ID, contents: '<h1>Page Not Found</h1>' };
7272
const { docService } = getServices('missing/doc');
7373
docService.currentDocument.subscribe(doc => currentDocument = doc);
@@ -82,7 +82,7 @@ describe('DocumentService', () => {
8282
});
8383

8484
it('should emit a hard-coded not-found document if the not-found document is not found on the server', () => {
85-
let currentDocument: DocumentContents;
85+
let currentDocument: DocumentContents|undefined;
8686
const hardCodedNotFoundDoc = { contents: 'Document not found', id: FILE_NOT_FOUND_ID };
8787
const nextDoc = { contents: 'Next Doc', id: 'new/doc' };
8888
const { docService, locationService } = getServices(FILE_NOT_FOUND_ID);
@@ -99,15 +99,15 @@ describe('DocumentService', () => {
9999
});
100100

101101
it('should use a hard-coded error doc if the request fails (but not cache it)', () => {
102-
let latestDocument: DocumentContents;
102+
let latestDocument: DocumentContents|undefined;
103103
const doc1 = { contents: 'doc 1' };
104104
const doc2 = { contents: 'doc 2' };
105105
const { docService, locationService } = getServices('initial/doc');
106106

107107
docService.currentDocument.subscribe(doc => latestDocument = doc);
108108

109109
httpMock.expectOne({}).flush(null, {status: 500, statusText: 'Server Error'});
110-
expect(latestDocument.id).toEqual(FETCHING_ERROR_ID);
110+
expect(latestDocument!.id).toEqual(FETCHING_ERROR_ID);
111111

112112
locationService.go('new/doc');
113113
httpMock.expectOne({}).flush(doc1);
@@ -119,22 +119,22 @@ describe('DocumentService', () => {
119119
});
120120

121121
it('should not crash the app if the response is invalid JSON', () => {
122-
let latestDocument: DocumentContents;
122+
let latestDocument: DocumentContents|undefined;
123123
const doc1 = { contents: 'doc 1' };
124124
const { docService, locationService } = getServices('initial/doc');
125125

126126
docService.currentDocument.subscribe(doc => latestDocument = doc);
127127

128128
httpMock.expectOne({}).flush('this is invalid JSON');
129-
expect(latestDocument.id).toEqual(FETCHING_ERROR_ID);
129+
expect(latestDocument!.id).toEqual(FETCHING_ERROR_ID);
130130

131131
locationService.go('new/doc');
132132
httpMock.expectOne({}).flush(doc1);
133133
expect(latestDocument).toEqual(jasmine.objectContaining(doc1));
134134
});
135135

136136
it('should not make a request to the server if the doc is in the cache already', () => {
137-
let latestDocument: DocumentContents;
137+
let latestDocument: DocumentContents|undefined;
138138
let subscription: Subscription;
139139

140140
const doc0 = { contents: 'doc 0' };

aio/src/app/documents/document.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class DocumentService {
5252
if ( !this.cache.has(id)) {
5353
this.cache.set(id, this.fetchDocument(id));
5454
}
55-
return this.cache.get(id);
55+
return this.cache.get(id)!;
5656
}
5757

5858
private fetchDocument(id: string): Observable<DocumentContents> {

aio/src/app/embed-components/embed-components.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ describe('EmbedComponentsService', () => {
127127
const componentRefs = service.createComponents(host);
128128
componentRefs[0].changeDetectorRef.detectChanges();
129129

130-
const barEl = host.querySelector('aio-eager-bar');
130+
const barEl = host.querySelector('aio-eager-bar')!;
131131

132-
expect(barEl['aioEagerBarContent']).toBe(projectedContent);
132+
expect((barEl as any)['aioEagerBarContent']).toBe(projectedContent);
133133
expect(barEl.innerHTML).toContain(projectedContent);
134134
});
135135

0 commit comments

Comments
 (0)