Files
Julian LechnerandClaude Opus 5.5 b6c33780c3 docs(rules): update TypeScript and Angular rules for TS 7 and trim duplicates
TypeScript 7.0 ships the native compiler as tsc and drops options
deprecated in 6.0. Angular 22 still requires TypeScript >=6.0.0 <6.1.0,
so both rule sets now warn against moving Angular projects to TS 7, and
the Angular index asks to check the Angular version first.

TypeScript runtime safety adds error handling (Error objects only,
cause chaining, unknown in catch, one error model per layer, no
swallowed errors) plus exact decimals for money, ISO 8601 UTC dates, and
Intl formatting. Angular adds per-route SSR render modes, a global
ErrorHandler with provideBrowserGlobalErrorListeners, and translatable
text with locale-aware formatting.

Generic guidance that the TypeScript, refactoring, and UI/UX rules
already cover is removed from the Angular rules, which shrink by about
7.5 percent despite the additions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 10:08:25 +01:00

3.6 KiB

Angular Components, Change Detection, and Signals

Apply these rules when creating or changing Angular components, directives, signal state, change detection, or DOM access.

Components

  • Prefer standalone components, directives, and pipes for new work. Avoid introducing NgModule unless the existing architecture requires it.
  • Keep components small; move substantial business logic to a focused service or domain layer.
  • Use ChangeDetectionStrategy.OnPush unless there is a concrete reason not to, in both zone.js and zoneless applications.
  • Keep component state minimal, update it immutably, and never mutate shared state directly.
  • In new code on Angular 19+, use input() and input.required(), output() (an OutputEmitterRef, not a signal), model() for intended two-way bindings, and signal queries (viewChild, viewChildren, contentChild, contentChildren). Keep @Input, @Output, and decorator queries only where the surrounding code uses them.
  • Use the host object in component metadata instead of @HostBinding and @HostListener in new code.
  • Prefer explicit data flow: inputs down, events up. Avoid unnecessary two-way binding, component coupling, and exposed internal state.
  • Use lifecycle hooks only when required, and keep constructors free of complex initialization.

Change Detection

  • Check whether the application uses zone.js or is zoneless: new applications are zoneless by default since Angular 21 (provideZonelessChangeDetection, stable since 20.2). Do not migrate between the two as a side effect of another task.
  • In zoneless applications, change template-bound state only through signals, markForCheck, the async pipe, or template event handlers. Mutating plain fields in setTimeout or promise callbacks does not update the view.
  • Do not add NgZone APIs (onStable, onMicrotaskEmpty, runOutsideAngular) for rendering logic; use afterNextRender or afterRenderEffect for DOM work after rendering.

Signals and State

  • Prefer signals for local and synchronous reactive state.
  • Derive values with computed instead of storing or duplicating them; keep computed free of side effects.
  • Keep signals private when external mutation is not intended, and expose readonly state where practical.
  • Avoid circular signal dependencies.
  • Use effect only for actual side effects, not as a replacement for normal data flow. Keep effects small and deterministic, and clean up resources they create.
  • Use linkedSignal (Angular 20+) for writable state that resets when a source changes, instead of an effect that writes signals.
  • For parameter-driven reads, use httpResource, resource, or rxResource (stable since Angular 22; experimental in 19 to 21, so use them there only if the project already does). Use RxJS for event streams, cancellation semantics, and multi-step flows; convert with toSignal at the component edge, in an injection context. Never perform writes or mutations through resources.
  • Do not use global state unless multiple unrelated parts of the application genuinely need it.
  • Do not introduce a state-management library without a clear requirement.

DOM and Browser APIs

  • Prefer Angular APIs and declarative templates over direct DOM manipulation; use Renderer2 only when a rendering abstraction is actually needed.
  • When the application uses SSR, guard window, document, localStorage, and similar browser-only APIs with isPlatformBrowser, or run DOM access in afterNextRender or afterRenderEffect, which run only in the browser.
  • Clean up event listeners, observers, and timers, and avoid layout thrashing in performance-sensitive code.