Skip to content

Commit c42322b

Browse files
Splaktarjosephperrott
authored andcommitted
refactor: enable stricter TypeScript compiler flags (#631)
align with the examples and the new CLI settings by enabling - `noImplicitAny` - `noImplicitReturns` - `noImplicitThis` - `noFallthroughCasesInSwitch` - `strictNullChecks` Relates to angular/angular-cli#14905
1 parent d87bfcb commit c42322b

File tree

19 files changed

+101
-74
lines changed

19 files changed

+101
-74
lines changed

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/component-list/component-list.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ import {combineLatest} from 'rxjs';
1616
styleUrls: ['./component-list.scss']
1717
})
1818
export class ComponentList {
19-
category: DocCategory;
19+
category: DocCategory | undefined;
2020
section: string;
2121

2222
constructor(public docItems: DocumentationItems,
2323
private _componentPageTitle: ComponentPageTitle,
2424
private _route: ActivatedRoute,
2525
public router: Router) {
2626
combineLatest(_route.pathFromRoot.map(route => route.params), Object.assign)
27-
.subscribe(p => {
28-
this.category = docItems.getCategoryById(p['id']);
29-
this.section = p['section'];
27+
.subscribe((routeData: {[key: string]: string}) => {
28+
this.category = docItems.getCategoryById(routeData['id']);
29+
this.section = routeData['section'];
3030

3131
if (this.category) {
3232
this._componentPageTitle.title = this.category.name;

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/component-sidenav/component-sidenav.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class ComponentSidenav implements OnInit {
6060
export class ComponentNav implements OnInit, OnDestroy {
6161

6262
@Input() params: Observable<Params>;
63-
expansions = {};
63+
expansions: {[key: string]: boolean} = {};
6464
private _onDestroy = new Subject<void>();
6565

6666
constructor(public docItems: DocumentationItems,
@@ -83,7 +83,7 @@ export class ComponentNav implements OnInit, OnDestroy {
8383
setExpansions(params: Params) {
8484
const categories = this.docItems.getCategories(params.section);
8585
for (const category of (categories || [])) {
86-
if (this.expansions[category.id] === true) {
86+
if (this.expansions[category.id]) {
8787
continue;
8888
}
8989

@@ -95,7 +95,7 @@ export class ComponentNav implements OnInit, OnDestroy {
9595
}
9696
}
9797

98-
if (this.expansions[category.id] === false) {
98+
if (!this.expansions[category.id]) {
9999
this.expansions[category.id] = match;
100100
}
101101
}

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/component-viewer/component-viewer.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ describe('ComponentViewer', () => {
4141
it('should set page title correctly', () => {
4242
const component = fixture.componentInstance;
4343
fixture.detectChanges();
44-
const expected = `${component.docItems.getItemById(docItemsId, 'material').name}`;
44+
const docItem = component.docItems.getItemById(docItemsId, 'material');
45+
if (docItem === undefined) {
46+
throw Error(`Unable to find DocItem: '${docItemsId}' in section: 'material'.`);
47+
}
48+
const expected = `${docItem.name}`;
4549
expect(component._componentPageTitle.title).toEqual(expected);
4650
});
4751
});

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/component-viewer/component-viewer.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,21 @@ export class ComponentViewer implements OnDestroy {
3535
public _componentPageTitle: ComponentPageTitle,
3636
public docItems: DocumentationItems,
3737
) {
38+
let params = [_route.params];
39+
if (_route.parent) {
40+
params.push(_route.parent.params);
41+
}
3842
// Listen to changes on the current route for the doc id (e.g. button/checkbox) and the
3943
// parent route for the section (material/cdk).
40-
combineLatest(_route.params, _route.parent.params).pipe(
44+
combineLatest(params).pipe(
4145
map((p: [Params, Params]) => ({id: p[0]['id'], section: p[1]['section']})),
4246
map(p => ({doc: docItems.getItemById(p.id, p.section), section: p.section}),
4347
takeUntil(this._destroyed))
4448
).subscribe(d => {
45-
this.componentDocItem = d.doc;
46-
if (this.componentDocItem) {
49+
if (d.doc !== undefined) {
50+
this.componentDocItem = d.doc;
4751
this._componentPageTitle.title = `${this.componentDocItem.name}`;
48-
this.componentDocItem.examples.length ?
52+
this.componentDocItem.examples && this.componentDocItem.examples.length ?
4953
this.sections.add('examples') :
5054
this.sections.delete('examples');
5155
} else {

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/guide-viewer/guide-viewer.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="docs-primary-header">
2-
<h1>{{guide.name}}</h1>
2+
<h1>{{guide?.name}}</h1>
33
</div>
44

55
<div class="docs-guide-wrapper">
66
<div class="docs-guide-toc-and-content">
7-
<doc-viewer class="docs-guide-content"
7+
<doc-viewer class="docs-guide-content"
88
(contentRendered)="toc.updateScrollPosition()"
9-
[documentUrl]="guide.document"></doc-viewer>
9+
[documentUrl]="guide?.document"></doc-viewer>
1010
<table-of-contents #toc container="guide-viewer"></table-of-contents>
1111
</div>
1212
</div>

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/guide-viewer/guide-viewer.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {DocsAppTestingModule} from '../../testing/testing-module';
77
const guideItemsId = 'getting-started';
88

99
const mockActivatedRoute = {
10-
fragment: Observable.create(observer => {
10+
fragment: new Observable(observer => {
1111
observer.complete();
1212
}),
13-
params: Observable.create(observer => {
13+
params: new Observable(observer => {
1414
observer.next({id: guideItemsId});
1515
observer.complete();
1616
})

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/pages/guide-viewer/guide-viewer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ import {ComponentPageTitle} from '../page-title/page-title';
1212
styleUrls: ['./guide-viewer.scss'],
1313
})
1414
export class GuideViewer implements OnInit {
15-
guide: GuideItem;
15+
guide: GuideItem | undefined;
1616

1717
constructor(_route: ActivatedRoute,
1818
private _componentPageTitle: ComponentPageTitle,
1919
private router: Router,
2020
public guideItems: GuideItems) {
2121
_route.params.subscribe(p => {
22-
this.guide = guideItems.getItemById(p['id']);
22+
const guideItem = guideItems.getItemById(p['id']);
23+
if (guideItem) {
24+
this.guide = guideItem;
25+
}
2326

2427
if (!this.guide) {
2528
this.router.navigate(['/guides']);
@@ -28,7 +31,9 @@ export class GuideViewer implements OnInit {
2831
}
2932

3033
ngOnInit(): void {
31-
this._componentPageTitle.title = this.guide.name;
34+
if (this.guide !== undefined) {
35+
this._componentPageTitle.title = this.guide.name;
36+
}
3237
}
3338
}
3439

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/shared/copier/copier.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class CopierService {
5454
private removeFake() {
5555
if (this.textarea) {
5656
document.body.removeChild(this.textarea);
57-
this.textarea = null;
57+
delete this.textarea;
5858
}
5959
}
6060
}

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/shared/doc-viewer/doc-viewer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class DocViewerTestComponent {
106106
documentUrl = 'http://material.angular.io/simple-doc.html';
107107
}
108108

109-
const FAKE_DOCS = {
109+
const FAKE_DOCS: {[key: string]: string} = {
110110
'http://material.angular.io/simple-doc.html': '<div>my docs page</div>',
111111
'http://material.angular.io/doc-with-example.html': `
112112
<div>Check out this example:</div>

material.angular.io/material.angular.io/material.angular.io/material.angular.io/material.angular.io/src/app/shared/doc-viewer/doc-viewer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ export class DocViewer implements OnDestroy {
107107
element, this._componentFactoryResolver, this._appRef, this._injector);
108108
let examplePortal = new ComponentPortal(componentClass, this._viewContainerRef);
109109
let exampleViewer = portalHost.attach(examplePortal);
110-
(exampleViewer.instance as ExampleViewer).example = example;
110+
if (example !== null) {
111+
(exampleViewer.instance as ExampleViewer).example = example;
112+
}
111113

112114
this._portalHosts.push(portalHost);
113115
});

0 commit comments

Comments
 (0)