Skip to content

chore(apps, napi): restrict global types to NodeJS in tsconfig#20064

Closed
overlookmotel wants to merge 1 commit intomainfrom
om/03-06-chore_apps_napi_restrict_global_types_to_nodejs_in_tsconfig
Closed

chore(apps, napi): restrict global types to NodeJS in tsconfig#20064
overlookmotel wants to merge 1 commit intomainfrom
om/03-06-chore_apps_napi_restrict_global_types_to_nodejs_in_tsconfig

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 6, 2026

Add "types": ["node"] to tsconfig.json in apps/oxfmt, apps/oxlint, napi/minify, napi/parser, and napi/transform.

This restricts auto-included global type declarations to @types/node only, preventing unintended ambient types from transitive @types/* packages from leaking into the type-checking scope.

This change was broken out from #19675.

Copy link
Member Author

overlookmotel commented Mar 6, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-linter Area - Linter A-parser Area - Parser A-cli Area - CLI A-minifier Area - Minifier A-transformer Area - Transformer / Transpiler A-formatter Area - Formatter labels Mar 6, 2026
@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Mar 6, 2026
@overlookmotel overlookmotel marked this pull request as ready for review March 6, 2026 09:35
@overlookmotel overlookmotel requested a review from camc314 as a code owner March 6, 2026 09:35
Copilot AI review requested due to automatic review settings March 6, 2026 09:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit TypeScript types scoping for several Node-focused packages to prevent unintended ambient @types/* leakage into compilation, improving type-check determinism across the workspace.

Changes:

  • Add "types": ["node"] to apps/oxfmt/tsconfig.json and apps/oxlint/tsconfig.json.
  • Add "types": ["node"] to N-API package tsconfigs: napi/minify, napi/parser, and napi/transform.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
napi/transform/tsconfig.json Restricts auto-included global types to Node.js only.
napi/parser/tsconfig.json Restricts auto-included global types to Node.js only.
napi/minify/tsconfig.json Restricts auto-included global types to Node.js only.
apps/oxlint/tsconfig.json Restricts auto-included global types to Node.js only (helps avoid transitive ambient type leaks).
apps/oxfmt/tsconfig.json Restricts auto-included global types to Node.js only (helps avoid transitive ambient type leaks).

@overlookmotel overlookmotel marked this pull request as draft March 6, 2026 09:39
@overlookmotel overlookmotel marked this pull request as ready for review March 6, 2026 09:41
@overlookmotel
Copy link
Member Author

overlookmotel commented Mar 6, 2026

@cam @Dunqing @leaysgur I've assigned to you all because TS is not my strong suit, so would appreciate it if someone could review and merge.

@camc314
Copy link
Contributor

camc314 commented Mar 6, 2026

This restricts auto-included global type declarations to @types/node only, preventing unintended ambient types from transitive @types/* packages from leaking into the type-checking scope.

tsgolint restricts types to [] how were we getting the type information before?

@overlookmotel
Copy link
Member Author

tsgolint restricts types to [] how were we getting the type information before?

No idea! But I can conform that it was happening. If you neglected to import types like Node or Comment, it'd pick up global types with the same name from somewhere (browser globals?).

@camc314
Copy link
Contributor

camc314 commented Mar 6, 2026

Hmm I still don't understand this change - if i add types: node to the tsconfig, i still get Comment in the global scope - is this what you're expecting?

Furthermore is having node in the globals correct? We can't guarantee that these packages are always running in node - they might be running in the browser ect.

@camc314
Copy link
Contributor

camc314 commented Mar 6, 2026

@overlookmotel I think we want this instead: #20071

@leaysgur
Copy link
Member

leaysgur commented Mar 6, 2026

👍🏻 for #20071

@overlookmotel
Copy link
Member Author

I don't really understand this tsconfig business. I didn't write it - this was part of Sapphi's PR #19675. I've just split that PR up into 4 PRs to make it easier to disentangle and look at each piece in isolation.

And yeah you're right, it doesn't seem to stop e.g. Node being resolved as the DOM node type anyway. I assume #20071 does.

The rest of the stack works without this anyway. I'm going to remove this PR from the stack and continue revising the rest.

@overlookmotel overlookmotel deleted the om/03-06-chore_apps_napi_restrict_global_types_to_nodejs_in_tsconfig branch March 6, 2026 14:38
graphite-app bot pushed a commit that referenced this pull request Mar 6, 2026
Replaces #20064

The `dom` lib was implicitly being injected, this means stuff like `Token` and `Comment` were in the global scope, which was incorrect.

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

Labels

A-cli Area - CLI A-formatter Area - Formatter A-linter Area - Linter A-minifier Area - Minifier A-parser Area - Parser A-transformer Area - Transformer / Transpiler C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants