build(docs-infra): make type-checking stricter by enabling `noImplicitAny` (#29926)

PR Close #29926
This commit is contained in:
George Kalpakas 2019-04-24 15:27:24 +03:00 committed by Andrew Kushnir
parent 2002db28ff
commit eb85c8a742
16 changed files with 47 additions and 32 deletions

View File

@ -101,6 +101,7 @@
"@types/jasmine": "^2.5.52",
"@types/jasminewd2": "^2.0.4",
"@types/node": "~6.0.60",
"@types/xregexp": "^3.0.29",
"@yarnpkg/lockfile": "^1.1.0",
"archiver": "^1.3.0",
"canonical-path": "1.0.0",

View File

@ -652,11 +652,11 @@ describe('AppComponent', () => {
component.tocMaxHeight = '100';
fixture.detectChanges();
expect(tocContainer!.style['max-height']).toBe('100px');
expect(tocContainer!.style.maxHeight).toBe('100px');
component.tocMaxHeight = '200';
fixture.detectChanges();
expect(tocContainer!.style['max-height']).toBe('200px');
expect(tocContainer!.style.maxHeight).toBe('200px');
});
it('should restrain scrolling inside the ToC container', () => {

View File

@ -1,5 +1,5 @@
/* tslint:disable component-selector */
import { Component, AfterViewInit, ViewChild, Input, ViewChildren, QueryList, OnInit } from '@angular/core';
import { AfterViewInit, Component, ElementRef, Input, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
import { CodeComponent } from './code.component';
export interface TabInfo {
@ -48,7 +48,7 @@ export class CodeTabsComponent implements OnInit, AfterViewInit {
@Input() linenums: string;
@ViewChild('content', { static: true }) content;
@ViewChild('content', { static: true }) content: ElementRef;
@ViewChildren(CodeComponent) codeComponents: QueryList<CodeComponent>;

View File

@ -249,7 +249,7 @@ class FakeComponentFactory extends ComponentFactory<any> {
}
class FakeComponentFactoryResolver extends ComponentFactoryResolver {
constructor(private modulePath) { super(); }
constructor(private modulePath: string) { super(); }
resolveComponentFactory(component: Type<any>): ComponentFactory<any> {
return new FakeComponentFactory(this.modulePath);
@ -261,7 +261,7 @@ class FakeModuleRef extends NgModuleRef<WithCustomElementComponent> {
componentFactoryResolver = new FakeComponentFactoryResolver(this.modulePath);
instance: WithCustomElementComponent = new FakeCustomElementModule();
constructor(private modulePath) {
constructor(private modulePath: string) {
super();
this.injector.get.and.returnValue(this.componentFactoryResolver);
@ -275,7 +275,7 @@ class FakeModuleFactory extends NgModuleFactory<any> {
moduleType: Type<any>;
moduleRefToCreate = new FakeModuleRef(this.modulePath);
constructor(private modulePath) { super(); }
constructor(private modulePath: string) { super(); }
create(parentInjector: Injector | null): NgModuleRef<any> {
return this.moduleRefToCreate;

View File

@ -41,7 +41,7 @@ const DEFAULT_NS = '$$default';
export class CustomIconRegistry extends MatIconRegistry {
private preloadedSvgElements: SvgIconMap = {[DEFAULT_NS]: {}};
constructor(http: HttpClient, sanitizer: DomSanitizer, @Optional() @Inject(DOCUMENT) document,
constructor(http: HttpClient, sanitizer: DomSanitizer, @Optional() @Inject(DOCUMENT) document: Document,
@Inject(SVG_ICONS) svgIcons: SvgIconInfo[]) {
super(http, sanitizer, document);
this.loadSvgElements(svgIcons);

View File

@ -23,7 +23,7 @@ describe(browser.baseUrl, () => {
});
describe('(marketing pages)', () => {
const textPerUrl = {
const textPerUrl: { [key: string]: string } = {
features: 'features & benefits',
docs: 'what is angular?',
events: 'events',
@ -41,7 +41,7 @@ describe(browser.baseUrl, () => {
});
describe('(docs pages)', () => {
const textPerUrl = {
const textPerUrl: { [key: string]: string } = {
api: 'api list',
'guide/architecture': 'architecture',
'guide/http': 'httpclient',
@ -61,7 +61,7 @@ describe(browser.baseUrl, () => {
});
describe('(api docs pages)', () => {
const textPerUrl = {
const textPerUrl: { [key: string]: string } = {
/* Class */ 'api/core/Injector': 'class injector',
/* Const */ 'api/forms/NG_VALIDATORS': 'const ng_validators',
/* Decorator */ 'api/core/Component': '@component',

View File

@ -4,6 +4,7 @@
"module": "commonjs"
},
"include": [
"../shared/**/*.d.ts",
"**/*.ts"
]
}

View File

@ -0,0 +1,3 @@
declare module 'cjson' {
const load: (path: string) => { [key: string]: any };
}

View File

@ -4,6 +4,7 @@
"module": "commonjs"
},
"include": [
"../shared/**/*.d.ts",
"**/*.ts"
]
}

View File

@ -28,15 +28,15 @@ export class ApiPage extends SitePage {
return element.all(by.css(selector)).map<string>(item => item && item.getText());
}
getOverview(docType) {
getOverview(docType: string) {
return element(by.css(`.${docType}-overview`));
}
getSection(cls) {
getSection(cls: string) {
return element(by.css(`section.${cls}`));
}
getBadge(cls) {
getBadge(cls: string) {
return element(by.css('.api-status-label.' + cls));
}
}

View File

@ -33,12 +33,12 @@ export class SitePage {
const script = `return arguments[0].parentNode.querySelector('${targetSelector}');`;
return element(() => browser.executeScript(script, heading));
}
getTopMenuLink(path) { return element(by.css(`aio-top-menu a[href="${path}"]`)); }
getTopMenuLink(path: string) { return element(by.css(`aio-top-menu a[href="${path}"]`)); }
ga() { return browser.executeScript('return window["ga"].q') as promise.Promise<any[][]>; }
locationPath() { return browser.executeScript('return document.location.pathname') as promise.Promise<string>; }
navigateTo(pageUrl) {
navigateTo(pageUrl: string) {
// Navigate to the page, disable animations, and wait for Angular.
return browser.get('/' + pageUrl)
.then(() => browser.executeScript('document.body.classList.add(\'no-animations\')'))
@ -49,7 +49,7 @@ export class SitePage {
return this.docViewer.getText();
}
getInnerHtml(elementFinder) {
getInnerHtml(elementFinder: ElementFinder) {
// `getInnerHtml` was removed from webDriver and this is the workaround.
// See https://github.com/angular/protractor/blob/master/CHANGELOG.md#breaking-changes
return browser.executeScript('return arguments[0].innerHTML;', elementFinder);

View File

@ -53,7 +53,7 @@ ZoneDelegate.prototype.invokeTask@https://example.com/packages/zone.js@0.8.18/di
forkInnerZoneWithAngularBehavior/zone._inner<.onInvokeTask@https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:4656:24
ZoneDelegate.prototype.invokeTask@https://example.com/packages/zone.js@0.8.18/dist/zone.js:424:17
Zone.prototype.runTask@https://example.com/packages/zone.js@0.8.18/dist/zone.js:192:28
drainMicroTaskQueue@https://example.com/packages/zone.js@0.8.18/dist/zone.js:602:25` });
drainMicroTaskQueue@https://example.com/packages/zone.js@0.8.18/dist/zone.js:602:25` } as Error);
expect(message).toEqual(`something terrible has happened. oh no. oh no.
AppComponent@app.component.ts:31:29
@ -80,7 +80,7 @@ createDirectiveInstance@core.umd.j`);
onInvokeTask
runTask
drainMicroTaskQueue
promiseReactionJob@[native code]` });
promiseReactionJob@[native code]` } as Error);
expect(message).toEqual(`something terrible has happened. oh no. oh no.
AppComponent
@ -104,7 +104,7 @@ cr`);
at Object.debugCreateRootView [as createRootView] (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:14079:12)
at ComponentFactory_.create (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:10998:46)
at ComponentFactoryBoundToModule.create (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:3958:29)
at ApplicationRef.bootstrap (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:5769:57)` });
at ApplicationRef.bootstrap (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:5769:57)` } as Error);
expect(message).toEqual(`something terrible has happened. oh no. oh no.
new AppComponent@app.component.ts:31:29
@ -124,7 +124,7 @@ createDirectiveInstance@core.u`);
at Object.debugCreateRootView [as createRootView] (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:14079:12)
at ComponentFactory_.create (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:10998:46)
at ComponentFactoryBoundToModule.create (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:3958:29)
at ApplicationRef.bootstrap (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:5769:57)` });
at ApplicationRef.bootstrap (https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:5769:57)` } as Error);
expect(message).toEqual(`something terrible has happened. oh no. oh no.
new AppComponent@app.component.ts:31:29
@ -156,7 +156,7 @@ ZoneDelegate.prototype.invokeTask@https://example.com/packages/zone.js@0.8.18/di
onInvokeTask@https://example.com/packages/@angular/core@5.0.0/bundles/core.umd.js:4656:24
ZoneDelegate.prototype.invokeTask@https://example.com/packages/zone.js@0.8.18/dist/zone.js:424:17
Zone.prototype.runTask@https://example.com/packages/zone.js@0.8.18/dist/zone.js:192:28
drainMicroTaskQueue@https://example.com/packages/zone.js@0.8.18/dist/zone.js:602:25` });
drainMicroTaskQueue@https://example.com/packages/zone.js@0.8.18/dist/zone.js:602:25` } as Error);
expect(message).toEqual(`something terrible has happened. oh no. oh no.
AppComponent@app.component.ts:31:29
@ -176,7 +176,7 @@ createDirectiveInstance@core.umd.j`);
at debugCreateRootView (eval code:14079:5)
at ComponentFactory_.prototype.create (eval code:10998:9)
at ComponentFactoryBoundToModule.prototype.create (eval code:3958:9)
at ApplicationRef.prototype.bootstrap (eval code:5769:9)` });
at ApplicationRef.prototype.bootstrap (eval code:5769:9)` } as Error);
expect(message).toEqual(`something terrible has happened. oh no. oh no.
AppComponent@???:31:21
@ -185,7 +185,7 @@ createDirectiveInstance@???:12049:5
createViewNodes@???`);
});
async function callOnError(message, url, line, column, error) {
async function callOnError(message: string, url?: string, line?: number, column?: number, error?: Error) {
await browser.executeScript(function() {
// reset the ga queue
(window as any).ga.q.length = 0;

View File

@ -1,7 +1,7 @@
import { SitePage } from './app.po';
describe('site search', () => {
let page;
let page: SitePage;
beforeEach(() => {
page = new SitePage();

View File

@ -1,5 +1,10 @@
import * as XRegExp from 'xregexp';
// The `XRegExp` typings are not accurate.
interface XRegExp extends RegExp {
xregexp: { captureNames?: string[] };
}
const dot = /\./g;
const star = /\*/g;
const doubleStar = /(^|\/)\*\*($|\/)/g; // e.g. a/**/b or **/b or a/** but not a**b
@ -36,7 +41,7 @@ export class FirebaseGlob {
.replace(possiblyEmptySegments, '(?:/|/.*/)') // deal with /**/ special cases
.replace(willBeStar, '*'); // other ** matches
this.pattern = `^${pattern}$`;
this.regex = XRegExp(this.pattern);
this.regex = XRegExp(this.pattern) as XRegExp;
} catch (e) {
throw new Error(`Error in FirebaseGlob: "${glob}" - ${e.message}`);
}
@ -47,17 +52,17 @@ export class FirebaseGlob {
}
match(url: string) {
const match = XRegExp.exec(url, this.regex);
const match = XRegExp.exec(url, this.regex) as ReturnType<typeof XRegExp.exec> & { [captured: string]: string };
if (match) {
const result = {};
const names = (this.regex as any).xregexp.captureNames || [];
names.forEach(name => result[name] = match[name]);
const result: { [key: string]: string } = {};
const names = this.regex.xregexp.captureNames || [];
names.forEach(name => result[name] = (match[name]));
return result;
}
}
}
function replaceModifiedPattern(_, modifier, pattern) {
function replaceModifiedPattern(_: string, modifier: string, pattern: string) {
switch (modifier) {
case '!':
throw new Error(`"not" expansions are not supported: "${_}"`);

View File

@ -20,7 +20,6 @@
],
"skipLibCheck": true,
"strict": true,
"noImplicitAny": false,
"noUnusedLocals": true,
// disabled because this is on by default in tsc 2.7 breaking our codebase - we need to refactor
"strictPropertyInitialization": false

View File

@ -433,6 +433,11 @@
"@types/source-list-map" "*"
source-map "^0.6.1"
"@types/xregexp@^3.0.29":
version "3.0.29"
resolved "https://registry.yarnpkg.com/@types/xregexp/-/xregexp-3.0.29.tgz#9f2f819712ab41fd8b434036ec4b14cbb9dbe654"
integrity sha512-mm6iZYQ1xbVBNsWq2VSMFuneRuO0k0wUqIT4ZfrtbD1Eb90DXmqBOPA/URyUHq6wsftxr8aXDJHTTHyyBBY95w==
"@webassemblyjs/ast@1.8.5":
version "1.8.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359"