From 5f1b49b806a38d2df7125f38f13846a4453d5b8b Mon Sep 17 00:00:00 2001 From: Rodrigo Rangel de Souza Date: Tue, 6 Oct 2026 21:13:54 -0300 Subject: [PATCH] fix(@schematics/angular): generate main.ts with lint-compatible error handling Use unknown catch callback parameters and block bodies in standalone and NgModule application templates. Cover both variants in application schematic tests. Closes #34267 --- .../files/module-files/src/main.ts.template | 4 +++- .../files/standalone-files/src/main.ts.template | 4 +++- .../schematics/angular/application/index_spec.ts | 15 +++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/schematics/angular/application/files/module-files/src/main.ts.template b/packages/schematics/angular/application/files/module-files/src/main.ts.template index 0fcb878b1e23..9274f2d1e16f 100644 --- a/packages/schematics/angular/application/files/module-files/src/main.ts.template +++ b/packages/schematics/angular/application/files/module-files/src/main.ts.template @@ -5,4 +5,6 @@ import { AppModule } from './app/app<%= typeSeparator %>module'; platformBrowser().bootstrapModule(AppModule, { <% if (!!viewEncapsulation) { %> defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %> }) - .catch(err => console.error(err)); + .catch((err: unknown) => { + console.error(err); + }); diff --git a/packages/schematics/angular/application/files/standalone-files/src/main.ts.template b/packages/schematics/angular/application/files/standalone-files/src/main.ts.template index 104fe6b29ae7..d845c778226e 100644 --- a/packages/schematics/angular/application/files/standalone-files/src/main.ts.template +++ b/packages/schematics/angular/application/files/standalone-files/src/main.ts.template @@ -3,4 +3,6 @@ import { appConfig } from './app/app.config'; import { App } from './app/app<%= suffix %>'; bootstrapApplication(App, appConfig) - .catch((err) => console.error(err)); + .catch((err: unknown) => { + console.error(err); + }); diff --git a/packages/schematics/angular/application/index_spec.ts b/packages/schematics/angular/application/index_spec.ts index ad2ba04ff348..0236636b42b6 100644 --- a/packages/schematics/angular/application/index_spec.ts +++ b/packages/schematics/angular/application/index_spec.ts @@ -696,13 +696,16 @@ describe('Application Schematic', () => { expect(config).toContain('provideRouter(routes)'); }); - it('should create a main.ts', async () => { - const options = { ...defaultOptions, standalone: true }; - const tree = await schematicRunner.runSchematic('application', options, workspaceTree); + for (const standalone of [true, false]) { + it(`should create a main.ts with an unknown catch parameter and a block body (standalone=${standalone})`, async () => { + const options = { ...defaultOptions, standalone }; + const tree = await schematicRunner.runSchematic('application', options, workspaceTree); - const main = tree.readContent('/projects/foo/src/main.ts'); - expect(main).toContain('bootstrapApplication'); - }); + const main = tree.readContent('/projects/foo/src/main.ts'); + expect(main).toContain(standalone ? 'bootstrapApplication' : 'bootstrapModule'); + expect(main).toMatch(/\.catch\(\(err: unknown\) => \{\s+console\.error\(err\);\s+\}\);/); + }); + } describe('standalone=false', () => { it('should add the provideZoneChangeDetection with event coalescing option by default with zone.js apps', async () => {