Skip to content

fix(@schematics/angular): generate main.ts with lint-compatible error handling - #34268

Closed
Hangell wants to merge 1 commit into
angular:mainfrom
Hangell:fix/schematics-main-catch-34267
Closed

Hangell wants to merge 1 commit into
angular:mainfrom
Hangell:fix/schematics-main-catch-34267

Conversation

@Hangell

@Hangell Hangell commented Oct 7, 2026 •

Copy link
Copy Markdown

PR Checklist

Documentation changes are not needed for this generated-code correction.

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Applications generated by ng new or ng generate application use an untyped catch callback and implicitly return console.error(err) in main.ts. With typed linting, this triggers @typescript-eslint/use-unknown-in-catch-callback-variable and @typescript-eslint/no-confusing-void-expression.

Closes #34267.

What is the new behavior?

Both standalone and NgModule application templates declare the rejection parameter as unknown and log the error inside a block body:

.catch((err: unknown) => {
  console.error(err);
});

Application schematic tests cover both variants and verify the explicit parameter type and block body. Bootstrap and error logging behavior are preserved. Existing applications do not require a migration.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Validation:

  • pnpm bazel test //packages/schematics/angular:test — passed.
  • ESLint and Prettier checks for application/index_spec.ts — passed.
  • git diff --check — passed.

The full pnpm bazel test //packages/... attempt was interrupted and reported 78 passing targets, 3 local failures, and 18 skipped targets. The failures are outside the changed files:

  • //packages/angular_devkit/core/node:test: NodeJsAsyncHost can watch expected 3 events but received 4.
  • //packages/angular_devkit/build_webpack:build_webpack_test: timeout.
  • //packages/ngtools/webpack:test: timeout.

The full suite did not pass. No end-to-end suite was run.

@google-cla

google-cla Bot commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the main.ts templates for both module-based and standalone Angular applications to explicitly type the caught error in the bootstrap .catch() block as unknown and wrap the handler in a block body. It also updates the corresponding schematic tests to verify this new structure for both standalone and non-standalone configurations. There are no review comments, and the changes look correct.

… handling

Use unknown catch callback parameters and block bodies in standalone and NgModule
application templates. Cover both variants in application schematic tests.

Closes angular#34267
@Hangell
Hangell force-pushed the fix/schematics-main-catch-34267 branch from d1dd6b4 to 5f1b49b Compare October 7, 2026 02:15
@alan-agius4

alan-agius4 commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for the contribution! Closing this PR per #34267 (comment), as we don't tailor the default ng new templates to non-default third-party ESLint presets.

@alan-agius4 alan-agius4 closed this Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two TS linting errors in main.ts

2 participants