advanced

Module augmentation

Extend third-party declarations intentionally and keep global or module patches reviewable.

Module augmentation extends declarations from another module. It is useful when frameworks expose extension points — adding request properties, theme tokens, or plugin hooks. The change is global to type checking, so keep patches small, documented, and close to the integration.

Incorrect augmentation may pass type checking while runtime objects still lack the property. Ambient declarations can leak into unrelated code.

On interviews: explain with a concrete example and name what interviewers probe in production code.

Common pitfalls: mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus safety or expressiveness versus maintainability. Checklist:

  • Use only for real extension points.
  • Keep declarations near integration.
  • Confirm runtime shape.