refactor: fix typescript strict flag failures in all tests (#30993)

Fixes all TypeScript failures caused by enabling the `--strict`
flag for test source files. We also want to enable the strict
options for tests as the strictness enforcement improves the
overall codehealth, unveiled common issues and additionally it
allows us to enable `strict` in the `tsconfig.json` that is picked
up by IDE's.

PR Close #30993
This commit is contained in:
Paul Gschwendtner 2019-06-14 12:19:09 +02:00 committed by Miško Hevery
parent 69a612d402
commit 647d7bdd88
38 changed files with 256 additions and 203 deletions

View File

@ -67,7 +67,7 @@ class ReentrantInterceptor implements HttpInterceptor {
});
});
it('initializes HttpClient properly', done => {
injector.get(HttpClient).get('/test', {responseType: 'text'}).subscribe(value => {
injector.get(HttpClient).get('/test', {responseType: 'text'}).subscribe((value: string) => {
expect(value).toBe('ok!');
done();
});
@ -76,7 +76,7 @@ class ReentrantInterceptor implements HttpInterceptor {
it('intercepts outbound responses in the order in which interceptors were bound', done => {
injector.get(HttpClient)
.get('/test', {observe: 'response', responseType: 'text'})
.subscribe(value => done());
.subscribe(() => done());
const req = injector.get(HttpTestingController).expectOne('/test') as TestRequest;
expect(req.request.headers.get('Intercepted')).toEqual('A,B');
req.flush('ok!');
@ -84,7 +84,7 @@ class ReentrantInterceptor implements HttpInterceptor {
it('intercepts inbound responses in the right (reverse binding) order', done => {
injector.get(HttpClient)
.get('/test', {observe: 'response', responseType: 'text'})
.subscribe(value => {
.subscribe((value: HttpResponse<string>) => {
expect(value.headers.get('Intercepted')).toEqual('B,A');
done();
});

View File

@ -149,7 +149,10 @@ describe('defaultComparator', () => {
expect(values.sort(defaultComparator)).toEqual([{key: false, value: 1}, {key: true, value: 3}]);
});
it('should sort numbers as strings in numerical ascending', () => {
const values = [{key: '2', value: 1}, {key: 1, value: 3}];
// We need to cast the values array to "any[]" because the object keys
// have no type overlap and the "Array.sort" expects all keys to have the
// same type when passed to the sort comparator.
const values = [{key: '2', value: 1}, {key: 1, value: 3}] as any[];
expect(values.sort(defaultComparator)).toEqual([{key: 1, value: 3}, {key: '2', value: 1}]);
});
});

View File

@ -31,15 +31,14 @@ const EXTRACT_GENERATED_TRANSLATIONS_REGEXP =
const diff = (a: Set<string>, b: Set<string>): Set<string> =>
new Set([...Array.from(a)].filter(x => !b.has(x)));
const extract =
(from: string, regex: any, transformFn: (match: any[], state?: Set<any>) => any) => {
const result = new Set<any>();
let item;
while ((item = regex.exec(from)) !== null) {
result.add(transformFn(item, result));
}
return result;
};
const extract = (from: string, regex: any, transformFn: (match: any[], state: Set<any>) => any) => {
const result = new Set<any>();
let item;
while ((item = regex.exec(from)) !== null) {
result.add(transformFn(item, result));
}
return result;
};
// verify that we extracted all the necessary translations
// and their ids match the ones extracted via 'ng xi18n'

View File

@ -10,6 +10,7 @@ import * as ng from '@angular/compiler-cli';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as ts from 'typescript';
import {TestSupport, expectNoDiagnostics, setup} from '../test_support';
type MockFiles = {
@ -52,7 +53,7 @@ describe('ng type checker', () => {
if (!diagnostics || !diagnostics.length) {
throw new Error('Expected a diagnostic error message');
} else {
const matches: (d: ng.Diagnostic) => boolean = typeof message === 'string' ?
const matches: (d: ng.Diagnostic | ts.Diagnostic) => boolean = typeof message === 'string' ?
d => ng.isNgDiagnostic(d)&& d.messageText == message :
d => ng.isNgDiagnostic(d) && message.test(d.messageText);
const matchingDiagnostics = diagnostics.filter(matches) as ng.Diagnostic[];

View File

@ -11,7 +11,7 @@ import * as ts from 'typescript';
import {CompilerHostAdapter, MetadataBundler, MetadataBundlerHost} from '../../src/metadata/bundler';
import {MetadataCollector} from '../../src/metadata/collector';
import {ClassMetadata, MetadataGlobalReferenceExpression, ModuleMetadata} from '../../src/metadata/schema';
import {ClassMetadata, MetadataEntry, MetadataGlobalReferenceExpression, ModuleMetadata} from '../../src/metadata/schema';
import {Directory, MockAotContext, MockCompilerHost} from '../mocks';
describe('compiler host adapter', () => {
@ -242,7 +242,7 @@ describe('metadata bundler', () => {
const deepIndexMetadata = host.getMetadataFor('/lib/deep/index') !;
// The unbundled metadata should reference symbols using the relative module path.
expect(deepIndexMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining({
expect(deepIndexMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining<MetadataEntry>({
statics: {
ngInjectableDef: {
__symbolic: 'call',
@ -258,7 +258,7 @@ describe('metadata bundler', () => {
// For the bundled metadata, the "sharedFn" symbol should not be referenced using the
// relative module path (like for unbundled), because the metadata bundle can be stored
// anywhere and it's not guaranteed that the relatively referenced files are present.
expect(bundledMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining({
expect(bundledMetadata.metadata['MyClass']).toEqual(jasmine.objectContaining<MetadataEntry>({
statics: {
ngInjectableDef: {
__symbolic: 'call',

View File

@ -7,7 +7,7 @@
*/
import {AbsoluteFsPath, resolve} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {AbsoluteSourceSpan, IdentifierKind, TopLevelIdentifier} from '@angular/compiler-cli/src/ngtsc/indexer';
import {AbsoluteSourceSpan, IdentifierKind, IndexedComponent, TopLevelIdentifier} from '@angular/compiler-cli/src/ngtsc/indexer';
import {ParseSourceFile} from '@angular/compiler/src/compiler';
import {NgtscTestEnvironment} from './env';
@ -43,7 +43,7 @@ runInEachFileSystem(() => {
const [[decl, indexedComp]] = Array.from(indexed.entries());
expect(decl.getText()).toContain('export class TestCmp {}');
expect(indexedComp).toEqual(jasmine.objectContaining({
expect(indexedComp).toEqual(jasmine.objectContaining<IndexedComponent>({
name: 'TestCmp',
selector: 'test-cmp',
file: new ParseSourceFile(componentContent, testSourceFile),

View File

@ -83,19 +83,21 @@ describe('ng program', () => {
const originalGetSourceFile = host.getSourceFile;
const cache = new Map<string, ts.SourceFile>();
host.getSourceFile = function(fileName: string): ts.SourceFile {
const sf = originalGetSourceFile.call(host, fileName) as ts.SourceFile;
if (sf) {
if (cache.has(sf.fileName)) {
const oldSf = cache.get(sf.fileName) !;
if (oldSf.getFullText() === sf.getFullText()) {
return oldSf;
host.getSourceFile = function(
fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile |
undefined {
const sf = originalGetSourceFile.call(host, fileName, languageVersion);
if (sf) {
if (cache.has(sf.fileName)) {
const oldSf = cache.get(sf.fileName) !;
if (oldSf.getFullText() === sf.getFullText()) {
return oldSf;
}
}
cache.set(sf.fileName, sf);
}
}
cache.set(sf.fileName, sf);
}
return sf;
};
return sf;
};
return host;
}
@ -196,12 +198,14 @@ describe('ng program', () => {
const host = ng.createCompilerHost({options});
const originalGetSourceFile = host.getSourceFile;
const fileCache = new Map<string, ts.SourceFile>();
host.getSourceFile = (fileName: string) => {
host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget) => {
if (fileCache.has(fileName)) {
return fileCache.get(fileName);
}
const sf = originalGetSourceFile.call(host, fileName);
fileCache.set(fileName, sf);
const sf = originalGetSourceFile.call(host, fileName, languageVersion);
if (sf !== undefined) {
fileCache.set(fileName, sf);
}
return sf;
};
@ -469,8 +473,8 @@ describe('ng program', () => {
host.writeFile =
(fileName: string, data: string, writeByteOrderMark: boolean,
onError: (message: string) => void|undefined,
sourceFiles: ReadonlyArray<ts.SourceFile>) => {
onError: ((message: string) => void) | undefined,
sourceFiles?: ReadonlyArray<ts.SourceFile>) => {
written.set(fileName, {original: sourceFiles, data});
};
const program = ng.createProgram(
@ -1095,15 +1099,15 @@ describe('ng program', () => {
});
const host = ng.createCompilerHost({options});
const originalGetSourceFile = host.getSourceFile;
host.getSourceFile =
(fileName: string, languageVersion: ts.ScriptTarget,
onError?: ((message: string) => void) | undefined): ts.SourceFile => {
// We should never try to load .ngfactory.ts files
if (fileName.match(/\.ngfactory\.ts$/)) {
throw new Error(`Non existent ngfactory file: ` + fileName);
}
return originalGetSourceFile.call(host, fileName, languageVersion, onError);
};
host.getSourceFile = (fileName: string, languageVersion: ts.ScriptTarget,
onError?: ((message: string) => void) | undefined): ts.SourceFile |
undefined => {
// We should never try to load .ngfactory.ts files
if (fileName.match(/\.ngfactory\.ts$/)) {
throw new Error(`Non existent ngfactory file: ` + fileName);
}
return originalGetSourceFile.call(host, fileName, languageVersion, onError);
};
const program = ng.createProgram({rootNames: allRootNames, options, host});
const structuralErrors = program.getNgStructuralDiagnostics();
expect(structuralErrors.length).toBe(1);

View File

@ -20,7 +20,8 @@ describe('StaticReflector', () => {
function init(
testData: {[key: string]: any} = DEFAULT_TEST_DATA,
decorators: {name: string, filePath: string, ctor: any}[] = [],
errorRecorder?: (error: any, fileName: string) => void, collectorOptions?: CollectorOptions) {
errorRecorder?: (error: any, fileName?: string) => void,
collectorOptions?: CollectorOptions) {
const symbolCache = new StaticSymbolCache();
host = new MockStaticSymbolResolverHost(testData, collectorOptions);
const summaryResolver = new MockSummaryResolver([]);
@ -618,7 +619,7 @@ describe('StaticReflector', () => {
`;
let error: any = undefined;
init(data, [], (err: any, filePath: string) => {
init(data, [], (err: any, filePath?: string) => {
expect(error).toBeUndefined();
error = err;
});

View File

@ -70,8 +70,7 @@ import {escapeRegExp, splitAtColon, stringify, utf8Encode} from '../src/util';
['\uDEEE', '\xED\xBB\xAE'],
['\uDFFF', '\xED\xBF\xBF'],
];
tests.forEach(
([input, output]: [string, string]) => { expect(utf8Encode(input)).toEqual(output); });
tests.forEach(([input, output]) => { expect(utf8Encode(input)).toEqual(output); });
});
});
@ -80,4 +79,4 @@ import {escapeRegExp, splitAtColon, stringify, utf8Encode} from '../src/util';
() => { expect(stringify(Object.create(null))).toEqual('object'); });
});
});
}
}

View File

@ -244,7 +244,7 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
});
it('should work on templates', () => {
const templateComment = Array.from(fixture.nativeElement.childNodes)
const templateComment = Array.from((fixture.nativeElement as HTMLElement).childNodes)
.find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE) !;
const lContext = loadLContext(templateComment);
expect(lContext).toBeDefined();
@ -252,7 +252,7 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
});
it('should work on ng-container', () => {
const ngContainerComment = Array.from(fixture.nativeElement.childNodes)
const ngContainerComment = Array.from((fixture.nativeElement as HTMLElement).childNodes)
.find(
(node: ChildNode) => node.nodeType === Node.COMMENT_NODE &&
node.textContent === `ng-container`) !;

View File

@ -42,8 +42,9 @@ describe('property interpolation', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const titles = Array.from(fixture.nativeElement.querySelectorAll('div[title]'))
.map((div: HTMLDivElement) => div.title);
const titles =
Array.from(<NodeListOf<HTMLDivElement>>fixture.nativeElement.querySelectorAll('div[title]'))
.map((div: HTMLDivElement) => div.title);
expect(titles).toEqual([
'a1b2c3d4e5f6g7h8i9j',
@ -194,7 +195,9 @@ describe('property interpolation', () => {
const fixture = TestBed.createComponent(AppComp);
fixture.detectChanges();
const titles = Array.from(fixture.nativeElement.querySelectorAll('img[title]'))
const titles = Array
.from(<NodeListOf<HTMLImageElement>>fixture.nativeElement.querySelectorAll(
'img[title]'))
.map((img: HTMLImageElement) => img.title);
expect(titles).toEqual([
@ -210,8 +213,9 @@ describe('property interpolation', () => {
'1',
]);
const others = Array.from(fixture.nativeElement.querySelectorAll('img[alt]'))
.map((img: HTMLImageElement) => img.alt);
const others =
Array.from(<NodeListOf<HTMLImageElement>>fixture.nativeElement.querySelectorAll('img[alt]'))
.map((img: HTMLImageElement) => img.alt);
expect(others).toEqual([
'a1b2c3d4e5f6g7h8i9j',

View File

@ -182,8 +182,8 @@ function getRendererFactory2(document: any): RendererFactory2 {
const rendererFactory = new ServerRendererFactory2(
eventManager, fakeNgZone, document, new ɵDomSharedStylesHost(document));
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function() {
const renderer = origCreateRenderer.apply(this, arguments);
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
renderer.destroyNode = () => {};
return renderer;
};

View File

@ -41,8 +41,9 @@ describe('text instructions', () => {
const fixture = TestBed.createComponent(App);
fixture.detectChanges();
const allTextContent = Array.from(fixture.nativeElement.querySelectorAll('div'))
.map((div: HTMLDivElement) => div.textContent);
const allTextContent =
Array.from((fixture.nativeElement as HTMLElement).querySelectorAll('div'))
.map((div: HTMLDivElement) => div.textContent);
expect(allTextContent).toEqual([
'a1b2c3d4e5f6g7h8i9j',

View File

@ -7,7 +7,7 @@
*/
import {CommonModule, DOCUMENT} from '@angular/common';
import {Compiler, Component, ComponentFactoryResolver, Directive, DoCheck, ElementRef, EmbeddedViewRef, ErrorHandler, NO_ERRORS_SCHEMA, NgModule, OnInit, Pipe, PipeTransform, QueryList, RendererFactory2, Sanitizer, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ɵi18nConfigureLocalize} from '@angular/core';
import {Compiler, Component, ComponentFactoryResolver, Directive, DoCheck, ElementRef, EmbeddedViewRef, ErrorHandler, NO_ERRORS_SCHEMA, NgModule, OnInit, Pipe, PipeTransform, QueryList, RendererFactory2, RendererType2, Sanitizer, TemplateRef, ViewChild, ViewChildren, ViewContainerRef, ɵi18nConfigureLocalize} from '@angular/core';
import {Input} from '@angular/core/src/metadata';
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
import {TestBed, TestComponentRenderer} from '@angular/core/testing';
@ -541,8 +541,8 @@ describe('ViewContainerRef', () => {
const _origRendererFactory = TestBed.get(RendererFactory2) as RendererFactory2;
const _origCreateRenderer = _origRendererFactory.createRenderer;
_origRendererFactory.createRenderer = function() {
const renderer = _origCreateRenderer.apply(_origRendererFactory, arguments);
_origRendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = _origCreateRenderer.call(_origRendererFactory, element, type);
renderer.destroyNode = () => {};
return renderer;
};

View File

@ -376,9 +376,8 @@ const DEFAULT_COMPONENT_ID = '1';
it('should allow a transition to use a function to determine what method to run and expose any parameter values',
() => {
const transitionFn =
(fromState: string, toState: string, element: any, params: {[key: string]: any}) => {
return params['doMatch'] == true;
};
(fromState: string, toState: string, element?: any,
params?: {[key: string]: any}) => { return params !['doMatch'] == true; };
@Component({
selector: 'if-cmp',

View File

@ -298,7 +298,8 @@ class ComplexItem {
});
describe('forEachOperation', () => {
function stringifyItemChange(record: any, p: number, c: number, originalIndex: number) {
function stringifyItemChange(
record: any, p: number | null, c: number | null, originalIndex: number) {
const suffix = originalIndex == null ? '' : ' [o=' + originalIndex + ']';
const value = record.item;
if (record.currentIndex == null) {
@ -311,11 +312,13 @@ class ComplexItem {
}
function modifyArrayUsingOperation(
arr: number[], endData: any[], prev: number, next: number) {
arr: number[], endData: any[], prev: number | null, next: number | null) {
let value: number = null !;
if (prev == null) {
value = endData[next];
arr.splice(next, 0, value);
// "next" index is guaranteed to be set since the previous index is
// not defined and therefore a new entry is added.
value = endData[next !];
arr.splice(next !, 0, value);
} else if (next == null) {
value = arr[prev];
arr.splice(prev, 1);
@ -336,7 +339,7 @@ class ComplexItem {
differ = differ.diff(endData) !;
const operations: string[] = [];
differ.forEachOperation((item: any, prev: number, next: number) => {
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
const value = modifyArrayUsingOperation(startData, endData, prev, next);
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
});
@ -359,7 +362,7 @@ class ComplexItem {
differ = differ.diff(endData) !;
const operations: string[] = [];
differ.forEachOperation((item: any, prev: number, next: number) => {
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
modifyArrayUsingOperation(startData, endData, prev, next);
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
});
@ -379,7 +382,7 @@ class ComplexItem {
differ = differ.diff(endData) !;
const operations: string[] = [];
differ.forEachOperation((item: any, prev: number, next: number) => {
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
modifyArrayUsingOperation(startData, endData, prev, next);
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
});
@ -400,7 +403,7 @@ class ComplexItem {
differ = differ.diff(endData) !;
const operations: string[] = [];
differ.forEachOperation((item: any, prev: number, next: number) => {
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
modifyArrayUsingOperation(startData, endData, prev, next);
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
});
@ -421,7 +424,7 @@ class ComplexItem {
differ = differ.diff(endData) !;
const operations: string[] = [];
differ.forEachOperation((item: any, prev: number, next: number) => {
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
modifyArrayUsingOperation(startData, endData, prev, next);
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
});
@ -447,7 +450,7 @@ class ComplexItem {
differ = differ.diff(endData) !;
const operations: string[] = [];
differ.forEachOperation((item: any, prev: number, next: number) => {
differ.forEachOperation((item: any, prev: number | null, next: number | null) => {
const value = modifyArrayUsingOperation(startData, endData, prev, next);
operations.push(stringifyItemChange(item, prev, next, item.previousIndex));
});

View File

@ -8,7 +8,7 @@
import {ResourceLoader, UrlResolver} from '@angular/compiler';
import {MockResourceLoader} from '@angular/compiler/testing';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, DebugElement, Directive, DoCheck, EventEmitter, HostBinding, Inject, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, Provider, RenderComponentType, Renderer, RendererFactory2, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, WrappedValue} from '@angular/core';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, DebugElement, Directive, DoCheck, EventEmitter, HostBinding, Inject, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, Provider, RenderComponentType, Renderer, RendererFactory2, RendererType2, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewChild, ViewContainerRef, WrappedValue} from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -1718,8 +1718,8 @@ function patchLoggingRenderer2(rendererFactory: RendererFactory2, log: RenderLog
}
(<any>rendererFactory).__patchedForLogging = true;
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function() {
const renderer = origCreateRenderer.apply(this, arguments);
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
if ((<any>renderer).__patchedForLogging) {
return renderer;
}

View File

@ -8,7 +8,7 @@
import {ɵAnimationEngine, ɵNoopAnimationStyleNormalizer} from '@angular/animations/browser';
import {MockAnimationDriver} from '@angular/animations/browser/testing';
import {NgZone, RendererFactory2} from '@angular/core';
import {NgZone, RendererFactory2, RendererType2} from '@angular/core';
import {NoopNgZone} from '@angular/core/src/zone/ng_zone';
import {EventManager, ɵDomRendererFactory2, ɵDomSharedStylesHost} from '@angular/platform-browser';
import {ɵAnimationRendererFactory} from '@angular/platform-browser/animations';
@ -37,8 +37,8 @@ export function getRendererFactory2(document: any): RendererFactory2 {
const rendererFactory =
new ɵDomRendererFactory2(eventManager, new ɵDomSharedStylesHost(document), 'dummyappid');
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function() {
const renderer = origCreateRenderer.apply(this, arguments);
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
renderer.destroyNode = () => {};
return renderer;
};
@ -86,8 +86,8 @@ export function patchLoggingRenderer2(rendererFactory: RendererFactory2, log: Re
}
(<any>rendererFactory).__patchedForLogging = true;
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function() {
const renderer = origCreateRenderer.apply(this, arguments);
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
if ((<any>renderer).__patchedForLogging) {
return renderer;
}

View File

@ -2604,7 +2604,7 @@ describe('style and class based bindings', () => {
const players: MockPlayer[] = [];
const buildFn =
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
oldPlayer: MockPlayer | null) => {
oldPlayer: Player | null) => {
const player = new MockPlayer(value);
players.push(player);
return player;
@ -2932,8 +2932,8 @@ describe('style and class based bindings', () => {
let currentPlayer: MockPlayer|null = null;
const buildFn =
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
existingPlayer: MockPlayer) => {
previousPlayer = existingPlayer;
existingPlayer: Player | null) => {
previousPlayer = existingPlayer as MockPlayer | null;
return currentPlayer = new MockPlayer(value);
};
@ -2962,8 +2962,8 @@ describe('style and class based bindings', () => {
let previousPlayer: MockPlayer|null = null;
const buildFn =
(element: HTMLElement, type: BindingType, value: any, firstRender: boolean,
existingPlayer: MockPlayer | null) => {
previousPlayer = existingPlayer;
existingPlayer: Player | null) => {
previousPlayer = existingPlayer as MockPlayer | null;
return currentPlayer = new MockPlayer(value);
};

View File

@ -67,7 +67,7 @@ if (browserDetection.supportsCustomElements) {
element.connectedCallback();
let eventValue: any = null;
element.addEventListener('some-event', (e: CustomEvent) => eventValue = e.detail);
element.addEventListener('some-event', (e: Event) => eventValue = (e as CustomEvent).detail);
strategy.events.next({name: 'some-event', value: 'event-value'});
expect(eventValue).toEqual('event-value');
@ -80,7 +80,7 @@ if (browserDetection.supportsCustomElements) {
expect(strategy.disconnectCalled).toBe(true);
let eventValue: any = null;
element.addEventListener('some-event', (e: CustomEvent) => eventValue = e.detail);
element.addEventListener('some-event', (e: Event) => eventValue = (e as CustomEvent).detail);
strategy.events.next({name: 'some-event', value: 'event-value'});
expect(eventValue).toEqual(null);

View File

@ -10,7 +10,7 @@ import {extractProjectableNodes} from '../src/extract-projectable-nodes';
describe('extractProjectableNodes()', () => {
let elem: HTMLElement;
let childNodes: NodeList;
let childNodes: ChildNode[];
const expectProjectableNodes = (matches: {[selector: string]: number[]}) => {
const selectors = Object.keys(matches);

View File

@ -8,7 +8,7 @@
import {fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors} from '@angular/forms';
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms';
import {Validators} from '@angular/forms/src/validators';
import {of } from 'rxjs';
@ -626,7 +626,7 @@ import {of } from 'rxjs';
c.controls[0].value != 'correct' ? {'broken': true} : null;
const c = new FormControl(null);
const g = new FormArray([c], simpleValidator);
const g = new FormArray([c], simpleValidator as ValidatorFn);
c.setValue('correct');

View File

@ -9,13 +9,13 @@
import {EventEmitter} from '@angular/core';
import {fakeAsync, tick} from '@angular/core/testing';
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {AbstractControl, AsyncValidatorFn, FormControl, FormGroup, Validators} from '@angular/forms';
import {FormArray} from '@angular/forms/src/model';
(function() {
function asyncValidator(expected: string, timeouts = {}) {
return (c: FormControl) => {
function asyncValidator(expected: string, timeouts = {}): AsyncValidatorFn {
return (c: AbstractControl) => {
let resolve: (result: any) => void = undefined !;
const promise = new Promise(res => { resolve = res; });
const t = (timeouts as any)[c.value] != null ? (timeouts as any)[c.value] : 0;
@ -31,7 +31,7 @@ import {FormArray} from '@angular/forms/src/model';
};
}
function asyncValidatorReturningObservable(c: FormControl) {
function asyncValidatorReturningObservable(c: AbstractControl) {
const e = new EventEmitter();
Promise.resolve(null).then(() => { e.emit({'async': true}); });
return e;

View File

@ -35,7 +35,7 @@ import {of } from 'rxjs';
};
}
function asyncValidatorReturningObservable(c: FormControl) {
function asyncValidatorReturningObservable(c: AbstractControl) {
const e = new EventEmitter();
Promise.resolve(null).then(() => { e.emit({'async': true}); });
return e;

View File

@ -329,35 +329,35 @@ import {first, map} from 'rxjs/operators';
const v = Validators.composeAsync(
[promiseValidator({'one': true}), promiseValidator({'two': true})]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
tick();
expect(errorMap).toEqual({'one': true, 'two': true});
expect(errorMap !).toEqual({'one': true, 'two': true});
}));
it('should normalize and evaluate async validator-directives correctly', fakeAsync(() => {
const v = Validators.composeAsync([normalizeAsyncValidator(
new AsyncValidatorDirective('expected', {'one': true}))]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
tick();
expect(errorMap).toEqual({'one': true});
expect(errorMap !).toEqual({'one': true});
}));
it('should return null when no errors', fakeAsync(() => {
const v = Validators.composeAsync([promiseValidator({'one': true})]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
tick();
expect(errorMap).toBeNull();
@ -366,13 +366,13 @@ import {first, map} from 'rxjs/operators';
it('should ignore nulls', fakeAsync(() => {
const v = Validators.composeAsync([promiseValidator({'one': true}), null !]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
tick();
expect(errorMap).toEqual({'one': true});
expect(errorMap !).toEqual({'one': true});
}));
});
@ -391,33 +391,33 @@ import {first, map} from 'rxjs/operators';
const v = Validators.composeAsync(
[observableValidator({'one': true}), observableValidator({'two': true})]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
expect(errorMap).toEqual({'one': true, 'two': true});
expect(errorMap !).toEqual({'one': true, 'two': true});
});
it('should normalize and evaluate async validator-directives correctly', () => {
const v = Validators.composeAsync(
[normalizeAsyncValidator(new AsyncValidatorDirective('expected', {'one': true}))]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors) !;
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors) !;
expect(errorMap).toEqual({'one': true});
expect(errorMap !).toEqual({'one': true});
});
it('should return null when no errors', () => {
const v = Validators.composeAsync([observableValidator({'one': true})]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('expected')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
expect(errorMap).toBeNull();
});
@ -425,12 +425,12 @@ import {first, map} from 'rxjs/operators';
it('should ignore nulls', () => {
const v = Validators.composeAsync([observableValidator({'one': true}), null !]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
expect(errorMap).toEqual({'one': true});
expect(errorMap !).toEqual({'one': true});
});
it('should wait for all validators before setting errors', fakeAsync(() => {
@ -441,18 +441,20 @@ import {first, map} from 'rxjs/operators';
const v = Validators.composeAsync(
[getTimerObs(100, {one: true}), getTimerObs(200, {two: true})]) !;
let errorMap: {[key: string]: any} = undefined !;
let errorMap: {[key: string]: any}|null = undefined !;
(v(new FormControl('invalid')) as Observable<ValidationErrors|null>)
.pipe(first())
.subscribe((errors: {[key: string]: any}) => errorMap = errors);
.subscribe((errors: {[key: string]: any} | null) => errorMap = errors);
tick(100);
expect(errorMap).not.toBeDefined(
`Expected errors not to be set until all validators came back.`);
tick(100);
expect(errorMap).toEqual(
{one: true, two: true}, `Expected errors to merge once all validators resolved.`);
expect(errorMap !)
.toEqual(
{one: true, two: true},
`Expected errors to merge once all validators resolved.`);
}));
});

View File

@ -274,8 +274,9 @@ function buildUp(originalText: string, cb: (text: string, position: number) => v
inString[index] = true;
unused.splice(unusedIndex, 1);
let text = getText();
let position =
inString.filter((_, i) => i <= index).map(v => v ? 1 : 0).reduce((p, v) => p + v, 0);
let position = inString.filter((_, i) => i <= index)
.map(v => v ? 1 : 0)
.reduce((p: number, v) => p + v, 0);
cb(text, position);
}
}

View File

@ -115,13 +115,15 @@ class CompWithUrlTemplate {
{
describe('public testing API', () => {
describe('using the async helper with context passing', () => {
beforeEach(function() { this.actuallyDone = false; });
type TestContext = {actuallyDone: boolean};
afterEach(function() { expect(this.actuallyDone).toEqual(true); });
beforeEach(function(this: TestContext) { this.actuallyDone = false; });
it('should run normal tests', function() { this.actuallyDone = true; });
afterEach(function(this: TestContext) { expect(this.actuallyDone).toEqual(true); });
it('should run normal async tests', function(done) {
it('should run normal tests', function(this: TestContext) { this.actuallyDone = true; });
it('should run normal async tests', function(this: TestContext, done) {
setTimeout(() => {
this.actuallyDone = true;
done();
@ -129,9 +131,9 @@ class CompWithUrlTemplate {
});
it('should run async tests with tasks',
async(function() { setTimeout(() => this.actuallyDone = true, 0); }));
async(function(this: TestContext) { setTimeout(() => this.actuallyDone = true, 0); }));
it('should run async tests with promises', async(function() {
it('should run async tests with promises', async(function(this: TestContext) {
const p = new Promise((resolve, reject) => setTimeout(resolve, 10));
p.then(() => this.actuallyDone = true);
}));
@ -142,30 +144,35 @@ class CompWithUrlTemplate {
providers: [FancyService],
};
beforeEach(function() { this.contextModified = false; });
type TestContext = {contextModified: boolean};
afterEach(function() { expect(this.contextModified).toEqual(true); });
beforeEach(function(this: TestContext) { this.contextModified = false; });
afterEach(function(this: TestContext) { expect(this.contextModified).toEqual(true); });
it('should pass context to inject helper',
inject([], function() { this.contextModified = true; }));
inject([], function(this: TestContext) { this.contextModified = true; }));
it('should pass context to fakeAsync helper',
fakeAsync(function() { this.contextModified = true; }));
fakeAsync(function(this: TestContext) { this.contextModified = true; }));
it('should pass context to withModule helper - simple',
withModule(moduleConfig, function() { this.contextModified = true; }));
withModule(moduleConfig, function(this: TestContext) { this.contextModified = true; }));
it('should pass context to withModule helper - advanced',
withModule(moduleConfig).inject([FancyService], function(service: FancyService) {
expect(service.value).toBe('real value');
this.contextModified = true;
}));
withModule(moduleConfig)
.inject([FancyService], function(this: TestContext, service: FancyService) {
expect(service.value).toBe('real value');
this.contextModified = true;
}));
it('should preserve context when async and inject helpers are combined',
async(inject([], function() { setTimeout(() => this.contextModified = true, 0); })));
async(inject([], function(this: TestContext) {
setTimeout(() => this.contextModified = true, 0);
})));
it('should preserve context when fakeAsync and inject helpers are combined',
fakeAsync(inject([], function() {
fakeAsync(inject([], function(this: TestContext) {
setTimeout(() => this.contextModified = true, 0);
tick(1);
})));

View File

@ -776,7 +776,7 @@ class HiddenModule {
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
const http = ref.injector.get(HttpClient);
ref.injector.get<NgZone>(NgZone).run(() => {
http.get('http://localhost/testing').subscribe(body => {
http.get('http://localhost/testing').subscribe((body: string) => {
NgZone.assertInAngularZone();
expect(body).toEqual('success!');
});
@ -792,7 +792,7 @@ class HiddenModule {
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
const http = ref.injector.get(HttpClient);
ref.injector.get<NgZone>(NgZone).run(() => {
http.get('http://localhost/testing').subscribe(body => {
http.get('http://localhost/testing').subscribe((body: string) => {
expect(body).toEqual('success!');
});
expect(ref.injector.get<NgZone>(NgZone).hasPendingMacrotasks).toBeTruthy();
@ -809,7 +809,7 @@ class HiddenModule {
const mock = ref.injector.get(HttpTestingController) as HttpTestingController;
const http = ref.injector.get(HttpClient);
ref.injector.get<NgZone>(NgZone).run(() => {
http.get('http://localhost/testing').subscribe(body => {
http.get('http://localhost/testing').subscribe((body: string) => {
NgZone.assertInAngularZone();
expect(body).toEqual('success!');
});

View File

@ -118,7 +118,7 @@ describe('bootstrap', () => {
}
platformBrowserDynamic([]).bootstrapModule(TestModule).then(res => {
const router = res.injector.get(Router);
const router: Router = res.injector.get(Router);
expect(router.routerState.snapshot.root.firstChild).toBeNull();
// ResolveEnd has not been emitted yet because bootstrap returned too early
expect(log).toEqual([

View File

@ -3628,7 +3628,8 @@ describe('Integration', () => {
const recordedEvents: any[] = [];
const navStart$ = router.events.pipe(
tap(e => recordedEvents.push(e)), filter(e => e instanceof NavigationStart), first());
tap(e => recordedEvents.push(e)),
filter((e): e is NavigationStart => e instanceof NavigationStart), first());
navStart$.subscribe((e: NavigationStart | NavigationError) => {
router.navigate(

View File

@ -158,10 +158,15 @@ describe('Router', () => {
createActivatedRouteSnapshot({component: 'child', routeConfig: {path: 'child'}});
const futureState = new (RouterStateSnapshot as any)(
'url', new TreeNode(empty.root, [new TreeNode(childSnapshot, [])]));
// Since we only test the guards, we don't need to provide a full navigation
// transition object with all properties set.
const testTransition = {
guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())
} as NavigationTransition;
of ({guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())})
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
events.push(evt);
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
expect(result).toBe(true);
expect(events.length).toEqual(2);
@ -192,10 +197,15 @@ describe('Router', () => {
empty.root, [new TreeNode(childSnapshot, [
new TreeNode(grandchildSnapshot, [new TreeNode(greatGrandchildSnapshot, [])])
])]));
// Since we only test the guards, we don't need to provide a full navigation
// transition object with all properties set.
const testTransition = {
guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())
} as NavigationTransition;
of ({guards: getAllRouteGuards(futureState, empty, new ChildrenOutletContexts())})
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
events.push(evt);
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
expect(result).toBe(true);
expect(events.length).toEqual(6);
@ -224,10 +234,15 @@ describe('Router', () => {
'url',
new TreeNode(
empty.root, [new TreeNode(childSnapshot, [new TreeNode(grandchildSnapshot, [])])]));
// Since we only test the guards, we don't need to provide a full navigation
// transition object with all properties set.
const testTransition = {
guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())
} as NavigationTransition;
of ({guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())})
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
events.push(evt);
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
expect(result).toBe(true);
expect(events.length).toEqual(2);
@ -269,10 +284,15 @@ describe('Router', () => {
new TreeNode(
greatGrandchildSnapshot, [new TreeNode(greatGreatGrandchildSnapshot, [])])
])])]));
// Since we only test the guards, we don't need to provide a full navigation
// transition object with all properties set.
const testTransition = {
guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())
} as NavigationTransition;
of ({guards: getAllRouteGuards(futureState, currentState, new ChildrenOutletContexts())})
.pipe(checkGuardsOperator(TestBed, (evt) => { events.push(evt); }))
.subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
of (testTransition).pipe(checkGuardsOperator(TestBed, (evt) => {
events.push(evt);
})).subscribe((x) => result = !!x.guardsResult, (e) => { throw e; });
expect(result).toBe(true);
expect(events.length).toEqual(4);
@ -658,9 +678,11 @@ describe('Router', () => {
function checkResolveData(
future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: any, check: any): void {
// Since we only test the guards and their resolve data function, we don't need to provide
// a full navigation transition object with all properties set.
of ({
guards: getAllRouteGuards(future, curr, new ChildrenOutletContexts())
} as Partial<NavigationTransition>)
} as NavigationTransition)
.pipe(resolveDataOperator('emptyOnly', injector))
.subscribe(check, (e) => { throw e; });
}
@ -668,9 +690,11 @@ function checkResolveData(
function checkGuards(
future: RouterStateSnapshot, curr: RouterStateSnapshot, injector: any,
check: (result: boolean | UrlTree) => void): void {
// Since we only test the guards, we don't need to provide a full navigation
// transition object with all properties set.
of ({
guards: getAllRouteGuards(future, curr, new ChildrenOutletContexts())
} as Partial<NavigationTransition>)
} as NavigationTransition)
.pipe(checkGuardsOperator(injector))
.subscribe({
next(t) {

View File

@ -288,7 +288,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
mock.sendMessage({type, data: {message}});
const receivedMessages: string[] = [];
push.messages.subscribe((msg: {message: string}) => receivedMessages.push(msg.message));
push.messages.subscribe((msg: any) => receivedMessages.push(msg.message));
sendMessage('PUSH', 'this was a push message');
sendMessage('NOTPUSH', 'this was not a push message');

View File

@ -27,7 +27,7 @@ export class MockServiceWorkerContainer {
private onMessage: Function[] = [];
mockRegistration: MockServiceWorkerRegistration|null = null;
controller: MockServiceWorker|null = null;
messages = new Subject();
messages = new Subject<any>();
notificationClicks = new Subject();
addEventListener(event: 'controllerchange'|'message', handler: Function) {

View File

@ -4,7 +4,6 @@
{
"extends": "./tsconfig-build.json",
"compilerOptions": {
"strict": false,
"types": ["node", "jasmine"],
"plugins": [{
"name": "@bazel/tsetse",

View File

@ -7,6 +7,7 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"strict": true,
"moduleResolution": "node",
"strictNullChecks": true,
"strictPropertyInitialization": true,

View File

@ -1634,13 +1634,14 @@ withEachNg1Version(() => {
controllerAs: '$ctrl',
controller: class {$onInit() { $onInitSpyA(); }}
}))
.directive('ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function() { this.$onInit = $onInitSpyB; }
}))
.directive(
'ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function(this: any) { this.$onInit = $onInitSpyB; }
}))
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
@NgModule({
@ -1727,13 +1728,14 @@ withEachNg1Version(() => {
controllerAs: '$ctrl',
controller: class {$doCheck() { $doCheckSpyA(); }}
}))
.directive('ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function() { this.$doCheck = $doCheckSpyB; }
}))
.directive(
'ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function(this: any) { this.$doCheck = $doCheckSpyB; }
}))
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
@NgModule({
@ -1834,13 +1836,14 @@ withEachNg1Version(() => {
controllerAs: '$ctrl',
controller: class {$postLink() { $postLinkSpyA(); }}
}))
.directive('ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function() { this.$postLink = $postLinkSpyB; }
}))
.directive(
'ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function(this: any) { this.$postLink = $postLinkSpyB; }
}))
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
@NgModule({
@ -1929,7 +1932,7 @@ withEachNg1Version(() => {
scope: {valA: '<'},
bindToController: true,
controllerAs: '$ctrl',
controller: function($scope: angular.IScope) {
controller: function(this: any, $scope: angular.IScope) {
this.$onChanges = $onChangesControllerSpyA;
}
}))
@ -2034,13 +2037,14 @@ withEachNg1Version(() => {
controllerAs: '$ctrl',
controller: class {$onDestroy() { $onDestroySpyA(); }}
}))
.directive('ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function() { this.$onDestroy = $onDestroySpyB; }
}))
.directive(
'ng1B', () => ({
template: '',
scope: {},
bindToController: false,
controllerAs: '$ctrl',
controller: function(this: any) { this.$onDestroy = $onDestroySpyB; }
}))
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
@NgModule({

View File

@ -1166,8 +1166,8 @@ withEachNg1Version(() => {
constructor(injector: Injector) {
const originalGet = injector.get;
injector.get = function(token: any) {
if (token === NgZone) ++getNgZoneCount;
return originalGet.apply(injector, arguments);
if (arguments[0] === NgZone) ++getNgZoneCount;
return originalGet.apply(injector, arguments as any);
};
}
ngDoBootstrap() {}
@ -1192,9 +1192,9 @@ withEachNg1Version(() => {
const injector = ($injector.get(LAZY_MODULE_REF) as LazyModuleRef).injector !;
const injectorGet = injector.get;
spyOn(injector, 'get').and.callFake((...args: any[]) => {
expect(args[0]).not.toBe(NgZone);
return injectorGet.apply(injector, args);
spyOn(injector, 'get').and.callFake((...args: [any, any?]) => {
expect(args[0]).not.toBe(NgZone);
return injectorGet.apply(injector, args);
});
expect(element.textContent).toBe('Count: 1 | In the zone: true');

View File

@ -777,7 +777,7 @@ withEachNg1Version(() => {
C: {{ $ctrl.modelC }}
`,
bindings: {fullName: '@', modelA: '<dataA', modelB: '=dataB', modelC: '=', event: '&'},
controller: function($scope: angular.IScope) {
controller: function(this: any, $scope: angular.IScope) {
$scope.$watch('$ctrl.modelB', (v: string) => {
if (v === 'Savkin') {
this.modelB = 'SAVKIN';
@ -971,7 +971,7 @@ withEachNg1Version(() => {
const ng1Directive: angular.IDirective = {
template: '{{ someText }} - Data: {{ inputA }} - Length: {{ inputA.length }}',
scope: {inputA: '=', outputA: '&'},
controller: function($scope: angular.IScope) {
controller: function(this: any, $scope: angular.IScope) {
$scope['someText'] = 'ng1';
this.$scope = $scope;
}