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

build: enable strictTemplates, strictBindCallApply, and strictFunctionTypes #688

Merged
merged 1 commit into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/app/material-docs-app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Component, ViewEncapsulation} from '@angular/core';
import {Router, NavigationEnd} from '@angular/router';
import {Event, NavigationEnd, Router} from '@angular/router';
import {filter} from 'rxjs/operators';

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

router.events
.pipe(filter(event => event instanceof NavigationEnd))
.subscribe((data: NavigationEnd) => {
.pipe(filter((event: Event) => event instanceof NavigationEnd))
.subscribe((data: Event) => {
const urlAfterRedirects = (data as NavigationEnd).urlAfterRedirects;
// We want to reset the scroll position on navigation except when navigating within
// the documentation for a single component.
if (!isNavigationWithinComponentView(previousRoute, data.urlAfterRedirects)) {
if (!isNavigationWithinComponentView(previousRoute, urlAfterRedirects)) {
resetScrollPosition();
}

previousRoute = data.urlAfterRedirects;
ga.locationChanged(data.urlAfterRedirects);
previousRoute = urlAfterRedirects;
ga.locationChanged(urlAfterRedirects);
});
}
}
Expand Down
36 changes: 19 additions & 17 deletions src/app/pages/component-viewer/component-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,33 @@ export class ComponentViewer implements OnDestroy {
public _componentPageTitle: ComponentPageTitle,
public docItems: DocumentationItems,
) {
let params = [_route.params];
let routeAndParentParams = [_route.params];
if (_route.parent) {
params.push(_route.parent.params);
routeAndParentParams.push(_route.parent.params);
}
// Listen to changes on the current route for the doc id (e.g. button/checkbox) and the
// parent route for the section (material/cdk).
combineLatest(params).pipe(
map((p: [Params, Params]) => ({id: p[0]['id'], section: p[1]['section']})),
map(p => ({doc: docItems.getItemById(p.id, p.section), section: p.section}),
takeUntil(this._destroyed))
).subscribe(d => {
if (d.doc !== undefined) {
this.componentDocItem.next(d.doc);
this._componentPageTitle.title = `${d.doc.name}`;
d.doc.examples && d.doc.examples.length ?
this.sections.add('examples') :
this.sections.delete('examples');
} else {
this.router.navigate(['/' + d.section]);
}
});
combineLatest(routeAndParentParams).pipe(
map((params: Params[]) => ({id: params[0]['id'], section: params[1]['section']})),
map((docIdAndSection: {id: string, section: string}) =>
({doc: docItems.getItemById(docIdAndSection.id, docIdAndSection.section),
section: docIdAndSection.section}), takeUntil(this._destroyed))
).subscribe((docItemAndSection: {doc: DocItem | undefined, section: string}) => {
if (docItemAndSection.doc !== undefined) {
this.componentDocItem.next(docItemAndSection.doc);
this._componentPageTitle.title = `${docItemAndSection.doc.name}`;
docItemAndSection.doc.examples && docItemAndSection.doc.examples.length ?
this.sections.add('examples') :
this.sections.delete('examples');
} else {
this.router.navigate(['/' + docItemAndSection.section]);
}
});
}

ngOnDestroy(): void {
this._destroyed.next();
this._destroyed.complete();
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/table-of-contents/table-of-contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ export class TableOfContents implements OnInit, AfterViewInit, OnDestroy {
}

addHeaders(sectionName: string, docViewerContent: HTMLElement) {
const headers = docViewerContent.querySelectorAll('h3, h4');
const headers = Array.from<HTMLHeadingElement>(docViewerContent.querySelectorAll('h3, h4'));
const links: Link[] = [];
headers.forEach((header: HTMLElement) => {
headers.forEach((header) => {
// remove the 'link' icon name from the inner text
const name = header.innerText.trim().replace(/^link/, '');
const {top} = header.getBoundingClientRect();
Expand Down
19 changes: 11 additions & 8 deletions src/app/shared/theme-picker/theme-picker.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
Component,
ViewEncapsulation,
ChangeDetectionStrategy,
Component,
NgModule,
OnInit,
OnDestroy,
OnInit,
ViewEncapsulation,
} from '@angular/core';
import {StyleManager} from '../style-manager';
import {ThemeStorage, DocsSiteTheme} from './theme-storage/theme-storage';
import {DocsSiteTheme, ThemeStorage} from './theme-storage/theme-storage';
import {MatButtonModule} from '@angular/material/button';
import {MatGridListModule} from '@angular/material/grid-list';
import {MatIconModule} from '@angular/material/icon';
Expand All @@ -16,8 +16,7 @@ import {MatTooltipModule} from '@angular/material/tooltip';
import {CommonModule} from '@angular/common';
import {ActivatedRoute, ParamMap} from '@angular/router';
import {Subscription} from 'rxjs';
import {map, filter} from 'rxjs/operators';

import {map} from 'rxjs/operators';

@Component({
selector: 'theme-picker',
Expand Down Expand Up @@ -71,8 +70,12 @@ export class ThemePicker implements OnInit, OnDestroy {

ngOnInit() {
this._queryParamSubscription = this._activatedRoute.queryParamMap
.pipe(map((params: ParamMap) => params.get('theme')), filter(Boolean))
.subscribe((themeName: string) => this.installTheme(themeName));
.pipe(map((params: ParamMap) => params.get('theme')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous approach was valid, you just needed to do themeName! since it's guaranteed to be defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    this._queryParamSubscription = this._activatedRoute.queryParamMap
    .pipe(map((params: ParamMap) => params.get('theme')), filter(Boolean))
    .subscribe((themeName: string) => this.installTheme(themeName!));

Results in:

ERROR in src/app/shared/theme-picker/theme-picker.ts:74:16 - error TS2769: No overload matches this call.
  Overload 1 of 5, '(observer?: NextObserver<unknown> | ErrorObserver<unknown> | CompletionObserver<unknown> | undefined): Subscription', gave the following error.
    Argument of type '(themeName: string) => void' is not assignable to parameter of type 'NextObserver<unknown> | ErrorObserver<unknown> | CompletionObserver<unknown> | undefined'.
      Property 'complete' is missing in type '(themeName: string) => void' but required in type 'CompletionObserver<unknown>'.
  Overload 2 of 5, '(next?: ((value: unknown) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined): Subscription', gave the following error.
    Argument of type '(themeName: string) => void' is not assignable to parameter of type '(value: unknown) => void'.
      Types of parameters 'themeName' and 'value' are incompatible.
        Type 'unknown' is not assignable to type 'string'.

74     .subscribe((themeName: string) => this.installTheme(themeName!));
                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/rxjs/internal/types.d.ts:64:5
    64     complete: () => void;
           ~~~~~~~~
    'complete' is declared here.

This compiles, but is not great...

.subscribe((themeName: any) => this.installTheme(themeName));

.subscribe((themeName: string | null) => {
if (themeName) {
this.installTheme(themeName);
}
});
}

ngOnDestroy() {
Expand Down
10 changes: 7 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noFallthroughCasesInSwitch": true,
"strictNullChecks": true
"strictNullChecks": true,
"strictBindCallApply": true,
"strictFunctionTypes": true
},
"exclude": [
"src/assets"
"src/assets",
"dist"
],
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
"strictInjectionParameters": true,
"strictTemplates": true
}
}