diff --git a/packages/compiler/test/aot/compiler_spec.ts b/packages/compiler/test/aot/compiler_spec.ts index 6de379786a..97010dab8c 100644 --- a/packages/compiler/test/aot/compiler_spec.ts +++ b/packages/compiler/test/aot/compiler_spec.ts @@ -53,7 +53,7 @@ describe('compiler (unbundled Angular)', () => { function compileApp(): GeneratedFile { const {genFiles} = compile([rootDir, angularFiles]); return genFiles.find( - genFile => genFile.srcFileUrl === componentPath && genFile.genFileUrl.endsWith('.ts')); + genFile => genFile.srcFileUrl === componentPath && genFile.genFileUrl.endsWith('.ts'))!; } function findLineAndColumn( @@ -321,7 +321,7 @@ describe('compiler (unbundled Angular)', () => { const genFilePreamble = '/* Hello world! */'; const {genFiles} = compile([FILES, angularFiles]); const genFile = - genFiles.find(gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts')); + genFiles.find(gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts'))!; const genSource = toTypeScript(genFile, genFilePreamble); expect(genSource.startsWith(genFilePreamble)).toBe(true); }); @@ -440,7 +440,7 @@ describe('compiler (unbundled Angular)', () => { } }; const {genFiles} = compile([FILES, angularFiles]); - const genFile = genFiles.find(genFile => genFile.srcFileUrl === '/app/app.ts'); + const genFile = genFiles.find(genFile => genFile.srcFileUrl === '/app/app.ts')!; const genSource = toTypeScript(genFile); const createComponentFactoryCall = /ɵccf\([^)]*\)/m.exec(genSource) ![0].replace(/\s*/g, ''); // selector @@ -471,7 +471,7 @@ describe('compiler (unbundled Angular)', () => { }; const {genFiles} = compile([FILES, angularFiles]); const genFile = - genFiles.find(gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts')); + genFiles.find(gf => gf.srcFileUrl === '/app/app.ts' && gf.genFileUrl.endsWith('.ts'))!; const genSource = toTypeScript(genFile); expect(genSource).not.toContain('check('); @@ -510,7 +510,7 @@ describe('compiler (unbundled Angular)', () => { const {outDir: libOutDir} = compile([libInput, angularSummaryFiles], {useSummaries: true}); const {genFiles: appGenFiles} = compile([appInput, libOutDir, angularSummaryFiles], {useSummaries: true}); - const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts'); + const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts')!; const appNgFactoryTs = toTypeScript(appNgFactory); expect(appNgFactoryTs).not.toContain('AType'); expect(appNgFactoryTs).toContain('AValue'); @@ -557,7 +557,7 @@ describe('compiler (unbundled Angular)', () => { const {outDir: libOutDir} = compile([libInput, angularSummaryFiles], {useSummaries: true}); const {genFiles: appGenFiles} = compile([appInput, libOutDir, angularSummaryFiles], {useSummaries: true}); - const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts'); + const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts')!; const appNgFactoryTs = toTypeScript(appNgFactory); // metadata of ctor calls is preserved, so we reexport the argument @@ -598,7 +598,7 @@ describe('compiler (unbundled Angular)', () => { const {outDir: libOutDir} = compile([libInput, angularSummaryFiles], {useSummaries: true}); const {genFiles: appGenFiles} = compile([appInput, libOutDir, angularSummaryFiles], {useSummaries: true}); - const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts'); + const appNgFactory = appGenFiles.find((f) => f.genFileUrl === '/app/main.ngfactory.ts')!; const appNgFactoryTs = toTypeScript(appNgFactory); // we don't need to reexport exported symbols via the .ngfactory @@ -690,7 +690,7 @@ describe('compiler (unbundled Angular)', () => { compile([libInput, getAngularSummaryFiles()], {useSummaries: true}); const {genFiles} = compile([libOutDir, appInput, getAngularSummaryFiles()], {useSummaries: true}); - const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts'); + const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts')!; const flags = NodeFlags.TypeDirective | NodeFlags.Component | NodeFlags.OnDestroy; expect(toTypeScript(mainNgFactory)) .toContain(`${flags},(null as any),0,i1.Extends,[i2.AParam]`); @@ -743,7 +743,7 @@ describe('compiler (unbundled Angular)', () => { compile([lib1OutDir, lib2Input, getAngularSummaryFiles()], {useSummaries: true}); const {genFiles} = compile([lib2OutDir, appInput, getAngularSummaryFiles()], {useSummaries: true}); - const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts'); + const mainNgFactory = genFiles.find(gf => gf.srcFileUrl === '/app/main.ts')!; const flags = NodeFlags.TypeDirective | NodeFlags.Component | NodeFlags.OnDestroy; expect(toTypeScript(mainNgFactory)) .toContain(`${flags},(null as any),0,i1.Extends,[i2.AParam_2]`); diff --git a/packages/compiler/test/aot/jit_summaries_spec.ts b/packages/compiler/test/aot/jit_summaries_spec.ts index 699a484d3d..3ad70c4d3d 100644 --- a/packages/compiler/test/aot/jit_summaries_spec.ts +++ b/packages/compiler/test/aot/jit_summaries_spec.ts @@ -41,7 +41,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toContain(`import * as i0 from '/app/app.module'`); @@ -70,7 +70,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toContain(`import * as i0 from '/app/app.module'`); @@ -99,7 +99,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toContain(`import * as i0 from '/app/app.module'`); @@ -125,7 +125,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toContain(`import * as i0 from '/app/app.module'`); @@ -164,7 +164,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toMatch(/useClass:\{\s*reference:i1.MyService/); @@ -198,7 +198,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toMatch(/useClass:\{\s*reference:i1.MyService/); @@ -225,7 +225,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toMatch( @@ -247,7 +247,7 @@ describe('aot summaries for jit', () => { const rootDir = {'app': appDir}; const genFile = - compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts'); + compileApp(rootDir).genFiles.find(f => f.genFileUrl === '/app/app.module.ngsummary.ts')!; const genSource = toTypeScript(genFile); expect(genSource).toMatch( @@ -294,9 +294,9 @@ describe('aot summaries for jit', () => { }; const {outDir: lib3In, genFiles: lib2Gen} = compileApp(lib2In, {useSummaries: true}); - const lib2ModuleNgSummary = lib2Gen.find(f => f.genFileUrl === '/lib2/module.ngsummary.ts'); + const lib2ModuleNgSummary = lib2Gen.find(f => f.genFileUrl === '/lib2/module.ngsummary.ts')!; const lib2ReexportNgSummary = - lib2Gen.find(f => f.genFileUrl === '/lib2/reexport.ngsummary.ts'); + lib2Gen.find(f => f.genFileUrl === '/lib2/reexport.ngsummary.ts')!; // ngsummaries should add reexports for imported NgModules from a direct dependency expect(toTypeScript(lib2ModuleNgSummary)) @@ -325,9 +325,9 @@ describe('aot summaries for jit', () => { }; const lib3Gen = compileApp(lib3In, {useSummaries: true}).genFiles; - const lib3ModuleNgSummary = lib3Gen.find(f => f.genFileUrl === '/lib3/module.ngsummary.ts'); + const lib3ModuleNgSummary = lib3Gen.find(f => f.genFileUrl === '/lib3/module.ngsummary.ts')!; const lib3ReexportNgSummary = - lib3Gen.find(f => f.genFileUrl === '/lib3/reexport.ngsummary.ts'); + lib3Gen.find(f => f.genFileUrl === '/lib3/reexport.ngsummary.ts')!; // ngsummary.ts files should use the reexported values from direct and deep deps const lib3ModuleNgSummarySource = toTypeScript(lib3ModuleNgSummary); diff --git a/packages/compiler/test/aot/static_symbol_resolver_spec.ts b/packages/compiler/test/aot/static_symbol_resolver_spec.ts index 1c30215e70..531bbd0d45 100644 --- a/packages/compiler/test/aot/static_symbol_resolver_spec.ts +++ b/packages/compiler/test/aot/static_symbol_resolver_spec.ts @@ -422,7 +422,7 @@ export class MockSummaryResolver implements SummaryResolver { }[] = []) {} addSummary(summary: Summary) { this.summaries.push(summary); } resolveSummary(reference: StaticSymbol): Summary { - return this.summaries.find(summary => summary.symbol === reference); + return this.summaries.find(summary => summary.symbol === reference)!; } getSymbolsOf(filePath: string): StaticSymbol[]|null { const symbols = this.summaries.filter(summary => summary.symbol.filePath === filePath) diff --git a/packages/core/test/linker/integration_spec.ts b/packages/core/test/linker/integration_spec.ts index 9ac8ba617d..8313c73f81 100644 --- a/packages/core/test/linker/integration_spec.ts +++ b/packages/core/test/linker/integration_spec.ts @@ -412,7 +412,7 @@ function declareTests(config?: {useJit: boolean}) { const ngIfEl = fixture.debugElement.children[0]; const someViewport: SomeViewport = ngIfEl.childNodes - .find(debugElement => debugElement.nativeNode.nodeType === Node.COMMENT_NODE) + .find(debugElement => debugElement.nativeNode.nodeType === Node.COMMENT_NODE)! .injector.get(SomeViewport); expect(someViewport.container.length).toBe(2); expect(ngIfEl.children.length).toBe(2); @@ -812,7 +812,7 @@ function declareTests(config?: {useJit: boolean}) { }) .createComponent(MyComp); const tc = fixture.debugElement.childNodes.find( - debugElement => debugElement.nativeNode.nodeType === Node.COMMENT_NODE); + debugElement => debugElement.nativeNode.nodeType === Node.COMMENT_NODE)!; const emitter = tc.injector.get(DirectiveEmittingEvent); const myComp = fixture.debugElement.injector.get(MyComp); diff --git a/packages/core/test/render3/discovery_utils_spec.ts b/packages/core/test/render3/discovery_utils_spec.ts index d0e79dc790..10c795d7cb 100644 --- a/packages/core/test/render3/discovery_utils_spec.ts +++ b/packages/core/test/render3/discovery_utils_spec.ts @@ -315,7 +315,7 @@ describe('discovery utils', () => { it('should work on templates', () => { const templateComment = Array.from(fixture.hostElement.childNodes) - .find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE); + .find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE)!; const lContext = loadLContext(templateComment); expect(lContext).toBeDefined(); expect(lContext.native as any).toBe(templateComment); @@ -323,7 +323,7 @@ describe('discovery utils', () => { it('should work on ICU expressions', () => { const icuComment = Array.from(fixture.hostElement.querySelector('i18n') !.childNodes) - .find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE); + .find((node: ChildNode) => node.nodeType === Node.COMMENT_NODE)!; const lContext = loadLContext(icuComment); expect(lContext).toBeDefined(); expect(lContext.native as any).toBe(icuComment); @@ -333,7 +333,7 @@ describe('discovery utils', () => { const ngContainerComment = Array.from(fixture.hostElement.childNodes) .find( (node: ChildNode) => node.nodeType === Node.COMMENT_NODE && - node.textContent === `ng-container`); + node.textContent === `ng-container`)!; const lContext = loadLContext(ngContainerComment); expect(lContext).toBeDefined(); expect(lContext.native as any).toBe(ngContainerComment); diff --git a/packages/es6-subset.d.ts b/packages/es6-subset.d.ts index b1a9513c83..2f16198223 100644 --- a/packages/es6-subset.d.ts +++ b/packages/es6-subset.d.ts @@ -32,7 +32,7 @@ interface Array { * @param thisArg If provided, it will be used as the this value for each invocation of * predicate. If it is not provided, undefined is used instead. */ - find(predicate: (value: T, index: number, obj: Array) => boolean, thisArg?: any): T; + find(predicate: (value: T, index: number, obj: Array) => boolean, thisArg?: any): T|undefined; /** * Returns the this object after filling the section identified by start and end with value * @param value value to fill array section with