Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 5b26e24

Browse files
committed
build: enable strictTemplates, strictBindCallApply, and strictFunctionTypes
- fix related build errors - complete `this._destroyed` in `ngOnDestroy()` - exclude `dist/` from linting
1 parent c7eee2d commit 5b26e24

File tree

5 files changed

+46
-36
lines changed

5 files changed

+46
-36
lines changed

src/app/material-docs-app.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, ViewEncapsulation} from '@angular/core';
2-
import {Router, NavigationEnd} from '@angular/router';
2+
import {Event, NavigationEnd, Router} from '@angular/router';
33
import {filter} from 'rxjs/operators';
44

55
import {GaService} from './shared/ga/ga';
@@ -16,16 +16,17 @@ export class MaterialDocsApp {
1616
let previousRoute = router.routerState.snapshot.url;
1717

1818
router.events
19-
.pipe(filter(event => event instanceof NavigationEnd))
20-
.subscribe((data: NavigationEnd) => {
19+
.pipe(filter((event: Event) => event instanceof NavigationEnd))
20+
.subscribe((data: Event) => {
21+
const urlAfterRedirects = (data as NavigationEnd).urlAfterRedirects;
2122
// We want to reset the scroll position on navigation except when navigating within
2223
// the documentation for a single component.
23-
if (!isNavigationWithinComponentView(previousRoute, data.urlAfterRedirects)) {
24+
if (!isNavigationWithinComponentView(previousRoute, urlAfterRedirects)) {
2425
resetScrollPosition();
2526
}
2627

27-
previousRoute = data.urlAfterRedirects;
28-
ga.locationChanged(data.urlAfterRedirects);
28+
previousRoute = urlAfterRedirects;
29+
ga.locationChanged(urlAfterRedirects);
2930
});
3031
}
3132
}

src/app/pages/component-viewer/component-viewer.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,33 @@ export class ComponentViewer implements OnDestroy {
3636
public _componentPageTitle: ComponentPageTitle,
3737
public docItems: DocumentationItems,
3838
) {
39-
let params = [_route.params];
39+
let routeAndParentParams = [_route.params];
4040
if (_route.parent) {
41-
params.push(_route.parent.params);
41+
routeAndParentParams.push(_route.parent.params);
4242
}
4343
// Listen to changes on the current route for the doc id (e.g. button/checkbox) and the
4444
// parent route for the section (material/cdk).
45-
combineLatest(params).pipe(
46-
map((p: [Params, Params]) => ({id: p[0]['id'], section: p[1]['section']})),
47-
map(p => ({doc: docItems.getItemById(p.id, p.section), section: p.section}),
48-
takeUntil(this._destroyed))
49-
).subscribe(d => {
50-
if (d.doc !== undefined) {
51-
this.componentDocItem.next(d.doc);
52-
this._componentPageTitle.title = `${d.doc.name}`;
53-
d.doc.examples && d.doc.examples.length ?
54-
this.sections.add('examples') :
55-
this.sections.delete('examples');
56-
} else {
57-
this.router.navigate(['/' + d.section]);
58-
}
59-
});
45+
combineLatest(routeAndParentParams).pipe(
46+
map((params: Params[]) => ({id: params[0]['id'], section: params[1]['section']})),
47+
map((docIdAndSection: {id: string, section: string}) =>
48+
({doc: docItems.getItemById(docIdAndSection.id, docIdAndSection.section),
49+
section: docIdAndSection.section}), takeUntil(this._destroyed))
50+
).subscribe((docItemAndSection: {doc: DocItem | undefined, section: string}) => {
51+
if (docItemAndSection.doc !== undefined) {
52+
this.componentDocItem.next(docItemAndSection.doc);
53+
this._componentPageTitle.title = `${docItemAndSection.doc.name}`;
54+
docItemAndSection.doc.examples && docItemAndSection.doc.examples.length ?
55+
this.sections.add('examples') :
56+
this.sections.delete('examples');
57+
} else {
58+
this.router.navigate(['/' + docItemAndSection.section]);
59+
}
60+
});
6061
}
6162

6263
ngOnDestroy(): void {
6364
this._destroyed.next();
65+
this._destroyed.complete();
6466
}
6567
}
6668

src/app/shared/table-of-contents/table-of-contents.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ export class TableOfContents implements OnInit, AfterViewInit, OnDestroy {
107107
addHeaders(sectionName: string, docViewerContent: HTMLElement) {
108108
const headers = docViewerContent.querySelectorAll('h3, h4');
109109
const links: Link[] = [];
110-
headers.forEach((header: HTMLElement) => {
110+
headers.forEach((header: Element) => {
111111
// remove the 'link' icon name from the inner text
112-
const name = header.innerText.trim().replace(/^link/, '');
112+
const name = (header as HTMLElement).innerText.trim().replace(/^link/, '');
113113
const {top} = header.getBoundingClientRect();
114114
links.push({
115115
name,

src/app/shared/theme-picker/theme-picker.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
Component,
3-
ViewEncapsulation,
42
ChangeDetectionStrategy,
3+
Component,
54
NgModule,
6-
OnInit,
75
OnDestroy,
6+
OnInit,
7+
ViewEncapsulation,
88
} from '@angular/core';
99
import {StyleManager} from '../style-manager';
10-
import {ThemeStorage, DocsSiteTheme} from './theme-storage/theme-storage';
10+
import {DocsSiteTheme, ThemeStorage} from './theme-storage/theme-storage';
1111
import {MatButtonModule} from '@angular/material/button';
1212
import {MatGridListModule} from '@angular/material/grid-list';
1313
import {MatIconModule} from '@angular/material/icon';
@@ -16,8 +16,7 @@ import {MatTooltipModule} from '@angular/material/tooltip';
1616
import {CommonModule} from '@angular/common';
1717
import {ActivatedRoute, ParamMap} from '@angular/router';
1818
import {Subscription} from 'rxjs';
19-
import {map, filter} from 'rxjs/operators';
20-
19+
import {map} from 'rxjs/operators';
2120

2221
@Component({
2322
selector: 'theme-picker',
@@ -71,8 +70,12 @@ export class ThemePicker implements OnInit, OnDestroy {
7170

7271
ngOnInit() {
7372
this._queryParamSubscription = this._activatedRoute.queryParamMap
74-
.pipe(map((params: ParamMap) => params.get('theme')), filter(Boolean))
75-
.subscribe((themeName: string) => this.installTheme(themeName));
73+
.pipe(map((params: ParamMap) => params.get('theme')))
74+
.subscribe((themeName: string | null) => {
75+
if (themeName) {
76+
this.installTheme(themeName);
77+
}
78+
});
7679
}
7780

7881
ngOnDestroy() {

tsconfig.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
"noImplicitReturns": true,
2323
"noImplicitThis": true,
2424
"noFallthroughCasesInSwitch": true,
25-
"strictNullChecks": true
25+
"strictNullChecks": true,
26+
"strictBindCallApply": true,
27+
"strictFunctionTypes": true
2628
},
2729
"exclude": [
28-
"src/assets"
30+
"src/assets",
31+
"dist"
2932
],
3033
"angularCompilerOptions": {
3134
"fullTemplateTypeCheck": true,
32-
"strictInjectionParameters": true
35+
"strictInjectionParameters": true,
36+
"strictTemplates": true
3337
}
3438
}

0 commit comments

Comments
 (0)