Skip to content

Commit

Permalink
build(docs-infra): make type-checking stricter by enabling `noImplici…
Browse files Browse the repository at this point in the history
…tAny` (angular#29926)

PR Close angular#29926
  • Loading branch information
gkalpak authored and BioPhoton committed May 21, 2019
1 parent 0729faf commit 1c1b24a
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 32 deletions.
1 change: 1 addition & 0 deletions aio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions aio/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions aio/src/app/custom-elements/code/code-tabs.component.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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>;

Expand Down
6 changes: 3 additions & 3 deletions aio/src/app/custom-elements/elements-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion aio/src/app/shared/custom-icon-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions aio/tests/deployment/e2e/smoke-tests.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
1 change: 1 addition & 0 deletions aio/tests/deployment/e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "commonjs"
},
"include": [
"../shared/**/*.d.ts",
"**/*.ts"
]
}
3 changes: 3 additions & 0 deletions aio/tests/deployment/shared/cjson.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'cjson' {
const load: (path: string) => { [key: string]: any };
}
1 change: 1 addition & 0 deletions aio/tests/deployment/unit/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "commonjs"
},
"include": [
"../shared/**/*.d.ts",
"**/*.ts"
]
}
6 changes: 3 additions & 3 deletions aio/tests/e2e/src/api.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
6 changes: 3 additions & 3 deletions aio/tests/e2e/src/app.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\')'))
Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions aio/tests/e2e/src/onerror.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion aio/tests/e2e/src/search.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SitePage } from './app.po';

describe('site search', () => {
let page;
let page: SitePage;

beforeEach(() => {
page = new SitePage();
Expand Down
17 changes: 11 additions & 6 deletions aio/tools/firebase-test-utils/FirebaseGlob.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}`);
}
Expand All @@ -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: "${_}"`);
Expand Down
1 change: 0 additions & 1 deletion aio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions aio/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1c1b24a

Please sign in to comment.