diff --git a/packages/common/http/test/module_spec.ts b/packages/common/http/test/module_spec.ts index 1b0af18597..a6a66440f3 100644 --- a/packages/common/http/test/module_spec.ts +++ b/packages/common/http/test/module_spec.ts @@ -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) => { expect(value.headers.get('Intercepted')).toEqual('B,A'); done(); }); diff --git a/packages/common/test/pipes/keyvalue_pipe_spec.ts b/packages/common/test/pipes/keyvalue_pipe_spec.ts index 5d69e9929a..082fce6712 100644 --- a/packages/common/test/pipes/keyvalue_pipe_spec.ts +++ b/packages/common/test/pipes/keyvalue_pipe_spec.ts @@ -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}]); }); }); diff --git a/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts b/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts index 8465b86b40..37b9876369 100644 --- a/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts +++ b/packages/compiler-cli/test/compliance/r3_view_compiler_i18n_spec.ts @@ -31,15 +31,14 @@ const EXTRACT_GENERATED_TRANSLATIONS_REGEXP = const diff = (a: Set, b: Set): Set => new Set([...Array.from(a)].filter(x => !b.has(x))); -const extract = - (from: string, regex: any, transformFn: (match: any[], state?: Set) => any) => { - const result = new Set(); - 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) => { + const result = new Set(); + 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' diff --git a/packages/compiler-cli/test/diagnostics/check_types_spec.ts b/packages/compiler-cli/test/diagnostics/check_types_spec.ts index e03edfffcb..16e735939f 100644 --- a/packages/compiler-cli/test/diagnostics/check_types_spec.ts +++ b/packages/compiler-cli/test/diagnostics/check_types_spec.ts @@ -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[]; diff --git a/packages/compiler-cli/test/metadata/bundler_spec.ts b/packages/compiler-cli/test/metadata/bundler_spec.ts index 640caf558b..a3df9d15ee 100644 --- a/packages/compiler-cli/test/metadata/bundler_spec.ts +++ b/packages/compiler-cli/test/metadata/bundler_spec.ts @@ -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({ 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({ statics: { ngInjectableDef: { __symbolic: 'call', diff --git a/packages/compiler-cli/test/ngtsc/component_indexing_spec.ts b/packages/compiler-cli/test/ngtsc/component_indexing_spec.ts index d7abaad621..505e64c57a 100644 --- a/packages/compiler-cli/test/ngtsc/component_indexing_spec.ts +++ b/packages/compiler-cli/test/ngtsc/component_indexing_spec.ts @@ -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({ name: 'TestCmp', selector: 'test-cmp', file: new ParseSourceFile(componentContent, testSourceFile), diff --git a/packages/compiler-cli/test/transformers/program_spec.ts b/packages/compiler-cli/test/transformers/program_spec.ts index ca6d0c590b..248f1da3e5 100644 --- a/packages/compiler-cli/test/transformers/program_spec.ts +++ b/packages/compiler-cli/test/transformers/program_spec.ts @@ -83,19 +83,21 @@ describe('ng program', () => { const originalGetSourceFile = host.getSourceFile; const cache = new Map(); - 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(); - 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) => { + onError: ((message: string) => void) | undefined, + sourceFiles?: ReadonlyArray) => { 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); diff --git a/packages/compiler/test/aot/static_reflector_spec.ts b/packages/compiler/test/aot/static_reflector_spec.ts index a2eb196142..ced6e99bf1 100644 --- a/packages/compiler/test/aot/static_reflector_spec.ts +++ b/packages/compiler/test/aot/static_reflector_spec.ts @@ -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; }); diff --git a/packages/compiler/test/util_spec.ts b/packages/compiler/test/util_spec.ts index 60a6115429..5f082f04f9 100644 --- a/packages/compiler/test/util_spec.ts +++ b/packages/compiler/test/util_spec.ts @@ -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'); }); }); }); -} \ No newline at end of file +} diff --git a/packages/core/test/acceptance/discover_utils_spec.ts b/packages/core/test/acceptance/discover_utils_spec.ts index 6c13d569f0..f8b6fb2213 100644 --- a/packages/core/test/acceptance/discover_utils_spec.ts +++ b/packages/core/test/acceptance/discover_utils_spec.ts @@ -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`) !; diff --git a/packages/core/test/acceptance/property_interpolation_spec.ts b/packages/core/test/acceptance/property_interpolation_spec.ts index c360db6d53..0330f08a2a 100644 --- a/packages/core/test/acceptance/property_interpolation_spec.ts +++ b/packages/core/test/acceptance/property_interpolation_spec.ts @@ -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(>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(>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(>fixture.nativeElement.querySelectorAll('img[alt]')) + .map((img: HTMLImageElement) => img.alt); expect(others).toEqual([ 'a1b2c3d4e5f6g7h8i9j', diff --git a/packages/core/test/acceptance/renderer_factory_spec.ts b/packages/core/test/acceptance/renderer_factory_spec.ts index be26ca3543..5f55f4aabb 100644 --- a/packages/core/test/acceptance/renderer_factory_spec.ts +++ b/packages/core/test/acceptance/renderer_factory_spec.ts @@ -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; }; diff --git a/packages/core/test/acceptance/text_spec.ts b/packages/core/test/acceptance/text_spec.ts index 87f6d28664..9f666ef49a 100644 --- a/packages/core/test/acceptance/text_spec.ts +++ b/packages/core/test/acceptance/text_spec.ts @@ -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', diff --git a/packages/core/test/acceptance/view_container_ref_spec.ts b/packages/core/test/acceptance/view_container_ref_spec.ts index 0e672212f1..980e2af80c 100644 --- a/packages/core/test/acceptance/view_container_ref_spec.ts +++ b/packages/core/test/acceptance/view_container_ref_spec.ts @@ -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; }; diff --git a/packages/core/test/animation/animation_integration_spec.ts b/packages/core/test/animation/animation_integration_spec.ts index 809464e825..a35f3b2945 100644 --- a/packages/core/test/animation/animation_integration_spec.ts +++ b/packages/core/test/animation/animation_integration_spec.ts @@ -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', diff --git a/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts b/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts index e1d8f09063..8a9bf2a845 100644 --- a/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts +++ b/packages/core/test/change_detection/differs/default_iterable_differ_spec.ts @@ -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)); }); diff --git a/packages/core/test/linker/change_detection_integration_spec.ts b/packages/core/test/linker/change_detection_integration_spec.ts index 0602fb671c..a6450ee57b 100644 --- a/packages/core/test/linker/change_detection_integration_spec.ts +++ b/packages/core/test/linker/change_detection_integration_spec.ts @@ -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 } (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 ((renderer).__patchedForLogging) { return renderer; } diff --git a/packages/core/test/render3/imported_renderer2.ts b/packages/core/test/render3/imported_renderer2.ts index f6638d0e28..14ddcb19c3 100644 --- a/packages/core/test/render3/imported_renderer2.ts +++ b/packages/core/test/render3/imported_renderer2.ts @@ -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 } (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 ((renderer).__patchedForLogging) { return renderer; } diff --git a/packages/core/test/render3/styling/class_and_style_bindings_spec.ts b/packages/core/test/render3/styling/class_and_style_bindings_spec.ts index 99a59b0f82..1c12ea5e6b 100644 --- a/packages/core/test/render3/styling/class_and_style_bindings_spec.ts +++ b/packages/core/test/render3/styling/class_and_style_bindings_spec.ts @@ -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); }; diff --git a/packages/elements/test/create-custom-element_spec.ts b/packages/elements/test/create-custom-element_spec.ts index 4c6c938abe..34180a1e81 100644 --- a/packages/elements/test/create-custom-element_spec.ts +++ b/packages/elements/test/create-custom-element_spec.ts @@ -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); diff --git a/packages/elements/test/extract-projectable-nodes_spec.ts b/packages/elements/test/extract-projectable-nodes_spec.ts index ea172e1254..b03d9491a9 100644 --- a/packages/elements/test/extract-projectable-nodes_spec.ts +++ b/packages/elements/test/extract-projectable-nodes_spec.ts @@ -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); diff --git a/packages/forms/test/form_array_spec.ts b/packages/forms/test/form_array_spec.ts index fe89f77238..2066283b3a 100644 --- a/packages/forms/test/form_array_spec.ts +++ b/packages/forms/test/form_array_spec.ts @@ -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'); diff --git a/packages/forms/test/form_control_spec.ts b/packages/forms/test/form_control_spec.ts index 7b90a1e5a4..b56ce8edd6 100644 --- a/packages/forms/test/form_control_spec.ts +++ b/packages/forms/test/form_control_spec.ts @@ -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; diff --git a/packages/forms/test/form_group_spec.ts b/packages/forms/test/form_group_spec.ts index 9e6180fa6a..eef495c4b9 100644 --- a/packages/forms/test/form_group_spec.ts +++ b/packages/forms/test/form_group_spec.ts @@ -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; diff --git a/packages/forms/test/validators_spec.ts b/packages/forms/test/validators_spec.ts index 148157e2ba..0d3f118965 100644 --- a/packages/forms/test/validators_spec.ts +++ b/packages/forms/test/validators_spec.ts @@ -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) .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) .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) .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) .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) .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) .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) .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) .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) .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.`); })); }); diff --git a/packages/language-service/test/completions_spec.ts b/packages/language-service/test/completions_spec.ts index ca06e51c18..23919304fc 100644 --- a/packages/language-service/test/completions_spec.ts +++ b/packages/language-service/test/completions_spec.ts @@ -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); } } diff --git a/packages/platform-browser/test/testing_public_spec.ts b/packages/platform-browser/test/testing_public_spec.ts index a641b8ae6e..88564cf419 100644 --- a/packages/platform-browser/test/testing_public_spec.ts +++ b/packages/platform-browser/test/testing_public_spec.ts @@ -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); }))); diff --git a/packages/platform-server/test/integration_spec.ts b/packages/platform-server/test/integration_spec.ts index 56f46a609a..80ded7a44b 100644 --- a/packages/platform-server/test/integration_spec.ts +++ b/packages/platform-server/test/integration_spec.ts @@ -776,7 +776,7 @@ class HiddenModule { const mock = ref.injector.get(HttpTestingController) as HttpTestingController; const http = ref.injector.get(HttpClient); ref.injector.get(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).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).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).run(() => { - http.get('http://localhost/testing').subscribe(body => { + http.get('http://localhost/testing').subscribe((body: string) => { NgZone.assertInAngularZone(); expect(body).toEqual('success!'); }); diff --git a/packages/router/test/bootstrap.spec.ts b/packages/router/test/bootstrap.spec.ts index ea649d56a6..a3be5403c4 100644 --- a/packages/router/test/bootstrap.spec.ts +++ b/packages/router/test/bootstrap.spec.ts @@ -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([ diff --git a/packages/router/test/integration.spec.ts b/packages/router/test/integration.spec.ts index 3766ef7065..01ba960bca 100644 --- a/packages/router/test/integration.spec.ts +++ b/packages/router/test/integration.spec.ts @@ -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( diff --git a/packages/router/test/router.spec.ts b/packages/router/test/router.spec.ts index 56c13a4a28..f0b76a4a19 100644 --- a/packages/router/test/router.spec.ts +++ b/packages/router/test/router.spec.ts @@ -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) + } 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) + } as NavigationTransition) .pipe(checkGuardsOperator(injector)) .subscribe({ next(t) { diff --git a/packages/service-worker/test/comm_spec.ts b/packages/service-worker/test/comm_spec.ts index 05f28c759e..9333165a3b 100644 --- a/packages/service-worker/test/comm_spec.ts +++ b/packages/service-worker/test/comm_spec.ts @@ -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'); diff --git a/packages/service-worker/testing/mock.ts b/packages/service-worker/testing/mock.ts index 69f0e9bb0d..bf1540a9db 100644 --- a/packages/service-worker/testing/mock.ts +++ b/packages/service-worker/testing/mock.ts @@ -27,7 +27,7 @@ export class MockServiceWorkerContainer { private onMessage: Function[] = []; mockRegistration: MockServiceWorkerRegistration|null = null; controller: MockServiceWorker|null = null; - messages = new Subject(); + messages = new Subject(); notificationClicks = new Subject(); addEventListener(event: 'controllerchange'|'message', handler: Function) { diff --git a/packages/tsconfig-test.json b/packages/tsconfig-test.json index 4ca48743cc..49d6b9523f 100644 --- a/packages/tsconfig-test.json +++ b/packages/tsconfig-test.json @@ -4,7 +4,6 @@ { "extends": "./tsconfig-build.json", "compilerOptions": { - "strict": false, "types": ["node", "jasmine"], "plugins": [{ "name": "@bazel/tsetse", diff --git a/packages/tsconfig.json b/packages/tsconfig.json index 3b67f9672b..e9b7d309eb 100644 --- a/packages/tsconfig.json +++ b/packages/tsconfig.json @@ -7,6 +7,7 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "module": "commonjs", + "strict": true, "moduleResolution": "node", "strictNullChecks": true, "strictPropertyInitialization": true, diff --git a/packages/upgrade/src/dynamic/test/upgrade_spec.ts b/packages/upgrade/src/dynamic/test/upgrade_spec.ts index 28ce7155e7..51f36f34cd 100644 --- a/packages/upgrade/src/dynamic/test/upgrade_spec.ts +++ b/packages/upgrade/src/dynamic/test/upgrade_spec.ts @@ -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({ diff --git a/packages/upgrade/static/test/integration/downgrade_module_spec.ts b/packages/upgrade/static/test/integration/downgrade_module_spec.ts index cce3d68134..269bd614ac 100644 --- a/packages/upgrade/static/test/integration/downgrade_module_spec.ts +++ b/packages/upgrade/static/test/integration/downgrade_module_spec.ts @@ -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'); diff --git a/packages/upgrade/static/test/integration/upgrade_component_spec.ts b/packages/upgrade/static/test/integration/upgrade_component_spec.ts index fd291ee944..3cd1a44596 100644 --- a/packages/upgrade/static/test/integration/upgrade_component_spec.ts +++ b/packages/upgrade/static/test/integration/upgrade_component_spec.ts @@ -777,7 +777,7 @@ withEachNg1Version(() => { C: {{ $ctrl.modelC }} `, bindings: {fullName: '@', modelA: ' { 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; }