Skip to content

fix(third-parties): remove global Window augmentation to avoid type degradation#85556

Open
cosocaf wants to merge 1 commit into
vercel:canaryfrom
cosocaf:window-augmentation-issue
Open

fix(third-parties): remove global Window augmentation to avoid type degradation#85556
cosocaf wants to merge 1 commit into
vercel:canaryfrom
cosocaf:window-augmentation-issue

Conversation

@cosocaf
Copy link
Copy Markdown

@cosocaf cosocaf commented Oct 30, 2025

Fixes #85555

Summary

Removes the global Window augmentation in @next/third-parties that introduced a string index signature ([key: string]: any]),
which caused mapped types involving Window to collapse into { [k: string]: any }.
The change uses a local cast instead, preserving runtime behavior while maintaining type safety across the ecosystem.

Details

  • Deleted packages/third-parties/src/types/google.ts global Window declaration.
  • Updated google/ga.tsx and google/gtm.tsx to locally cast window as { [key: string]: Object[] } before accessing dynamic data layer keys.

No runtime behavior changes.

Rationale

  • The dataLayer key name is dynamic; declaring it globally adds no type safety.
  • The global index signature caused far-reaching type degradation in apps, DOM utilities, and libraries.
  • Removing it restores consistency with lib.dom.d.ts and avoids polluting global scope.

Notes

  • Jest-based type tests are out of scope; this fix only targets type definitions.
  • While this issue surfaced clearly with @types/jsdom, it applies equally to any consumer using Omit<Window, ...> or similar type operations.

… degradation

Removes the global `Window` augmentation in `@next/third-parties` that introduced a string index signature (`[key: string]: any]`),
which caused mapped types involving `Window` to collapse into `{ [k: string]: any }`.
The change uses a local cast instead, preserving runtime behavior while maintaining type safety across the ecosystem.

- Deleted `packages/third-parties/src/types/google.ts` global `Window` declaration.
- Updated `google/ga.tsx` and `google/gtm.tsx` to locally cast window as `{ [key: string]: Object[] }` before accessing dynamic data layer keys.

No runtime behavior changes.

- The `dataLayer` key name is dynamic; declaring it globally adds no type safety.
- The global index signature caused far-reaching type degradation in apps, DOM utilities, and libraries.
- Removing it restores consistency with `lib.dom.d.ts` and avoids polluting global scope.

- Jest-based type tests are out of scope; this fix only targets type definitions.
- While this issue surfaced clearly with `@types/jsdom`, it applies equally to any consumer using `Omit<Window, ...>` or similar type operations.
@ijjk
Copy link
Copy Markdown
Member

ijjk commented Oct 30, 2025

Allow CI Workflow Run

  • approve CI run for commit: 6d07c5c

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

1 similar comment
@ijjk
Copy link
Copy Markdown
Member

ijjk commented Oct 30, 2025

Allow CI Workflow Run

  • approve CI run for commit: 6d07c5c

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@next/third-parties global Window augmentation breaks type inference due to index signature interaction with TypeScript mapped types

2 participants