Skip to content

Commit d1dd6b4

Browse files
committed
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
1 parent 57d25aa commit d1dd6b4

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

‎packages/schematics/angular/application/files/module-files/src/main.ts.template‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ import { AppModule } from './app/app<%= typeSeparator %>module';
55
platformBrowser().bootstrapModule(AppModule, {
66
<% if (!!viewEncapsulation) { %> defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %>
77
})
8-
.catch(err => console.error(err));
8+
.catch((err: unknown) => {
9+
console.error(err);
10+
});

‎packages/schematics/angular/application/files/standalone-files/src/main.ts.template‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ import { appConfig } from './app/app.config';
33
import { App } from './app/app<%= suffix %>';
44

55
bootstrapApplication(App, appConfig)
6-
.catch((err) => console.error(err));
6+
.catch((err: unknown) => {
7+
console.error(err);
8+
});

‎packages/schematics/angular/application/index_spec.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,13 +696,16 @@ describe('Application Schematic', () => {
696696
expect(config).toContain('provideRouter(routes)');
697697
});
698698

699-
it('should create a main.ts', async () => {
700-
const options = { ...defaultOptions, standalone: true };
701-
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
699+
for (const standalone of [true, false]) {
700+
it(`should create a main.ts with an unknown catch parameter and a block body (standalone=${standalone})`, async () => {
701+
const options = { ...defaultOptions, standalone };
702+
const tree = await schematicRunner.runSchematic('application', options, workspaceTree);
702703

703-
const main = tree.readContent('/projects/foo/src/main.ts');
704-
expect(main).toContain('bootstrapApplication');
705-
});
704+
const main = tree.readContent('/projects/foo/src/main.ts');
705+
expect(main).toContain(standalone ? 'bootstrapApplication' : 'bootstrapModule');
706+
expect(main).toMatch(/\.catch\(\(err: unknown\) => \{\s+console\.error\(err\);\s+\}\);/);
707+
});
708+
}
706709

707710
describe('standalone=false', () => {
708711
it('should add the provideZoneChangeDetection with event coalescing option by default with zone.js apps', async () => {

0 commit comments

Comments
 (0)