Skip to content

fix(core): improve native TypeScript type definitions#35251

Draft
AgentEnder wants to merge 5 commits intomasterfrom
claude/fix-nx-32205-g9LY6
Draft

fix(core): improve native TypeScript type definitions#35251
AgentEnder wants to merge 5 commits intomasterfrom
claude/fix-nx-32205-g9LY6

Conversation

@AgentEnder
Copy link
Copy Markdown
Member

@AgentEnder AgentEnder commented Apr 10, 2026

Current Behavior

The native TypeScript type definitions in index.d.ts were auto-generated with minimal type information, using generic type aliases like ProjectFiles and JsInputs that obscured the actual underlying types. This made it harder for TypeScript consumers to understand the actual structure of data being passed to and returned from native functions.

Expected Behavior

TypeScript definitions should be explicit and clear about the actual types being used, with proper branded types for opaque native handles and expanded union types for input specifications. This improves IDE autocomplete, type checking, and developer experience.

Changes

  1. Added branded types for native handles: Created opaque branded interfaces (NxDbConnection, ParserArc, WriterArc, HashInstruction) to prevent accidental interchangeability of different ExternalObject<T> handles.

  2. Expanded type definitions: Replaced generic type aliases with explicit types:

    • ProjectFilesRecord<string, Array<FileData>>
    • JsInputsInputsInput | string | FileSetInput | RuntimeInput | EnvironmentInput | ExternalDependenciesInput | DepsOutputsInput | WorkingDirectoryInput
  3. Added NAPI type annotations: Updated Rust source files with #[napi(ts_type = "...")] and #[napi(ts_arg_type = "...")] attributes to explicitly specify TypeScript types for:

    • TaskHasher.constructor() and hashPlans() methods
    • WorkspaceContext.updateProjectFiles() method
    • Target.inputs and Project.namedInputs fields
    • NxJson.namedInputs field
    • FileMap and NxWorkspaceFiles structures
  4. Created DTS header file: Added dts-header.d.ts containing the branded type definitions, configured in package.json via the dtsHeaderFile option to ensure these types are included in the generated type definitions.

  5. Fixed return type: Changed TaskHasher.hashPlans() return type from NapiDashMap<string, HashDetails> to Record<string, HashDetails> for clarity.

Test Plan

Existing tests should pass. The changes are purely type definition improvements with no runtime behavior changes. TypeScript compilation should succeed with improved type checking accuracy.

Fixes 32205

https://claude.ai/code/session_01HRaZd7KV54jKh3BFr2ZdKu

claude added 3 commits April 10, 2026 15:19
The auto-generated `index.d.ts` from NAPI-RS referenced several types that
were never declared: `NxDbConnection`, `ParserArc`, `WriterArc`,
`HashInstruction`, `JsInputs`, `ProjectFiles`, `ProjectRootMappings`, and
`NapiDashMap`. This caused TypeScript compilation failures when consuming
the `nx` package.

For transparent types with concrete TypeScript equivalents (`JsInputs`,
`ProjectFiles`, `ProjectRootMappings`, `NapiDashMap`), add `#[napi(ts_type)]`
annotations to the Rust source so NAPI-RS generates correct inline types.

For opaque types only used inside `ExternalObject<T>` (`NxDbConnection`,
`ParserArc`, `WriterArc`, `HashInstruction`), add a global ambient `.d.ts`
file with branded interface declarations to preserve type safety.

Fixes #32205

https://claude.ai/code/session_01HRaZd7KV54jKh3BFr2ZdKu
…al declarations

Replace the ambient global native-bindings-types.d.ts with a dts header
file that gets prepended to the generated index.d.ts by napi-rs. This
keeps the branded types (NxDbConnection, ParserArc, WriterArc,
HashInstruction) scoped to the module rather than leaking them into
the global namespace for consumers of nx.

https://claude.ai/code/session_01HRaZd7KV54jKh3BFr2ZdKu
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 10, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f1cd6a8
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69d942477cdde70008ed869d
😎 Deploy Preview https://deploy-preview-35251--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 10, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit f1cd6a8
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69d9424787f7a00007c985bc
😎 Deploy Preview https://deploy-preview-35251--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud bot commented Apr 10, 2026

View your CI Pipeline Execution ↗ for commit f1cd6a8

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ❌ Failed 55m 26s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx conformance:check ✅ Succeeded 7s View ↗
nx build workspace-plugin ✅ Succeeded 1m 30s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-10 19:33:49 UTC

nx-cloud[bot]

This comment was marked as outdated.

@AgentEnder AgentEnder changed the title refactor(nx): improve native TypeScript type definitions fix(core): improve native TypeScript type definitions Apr 10, 2026
Adds a regression test that runs TypeScript's type checker against the
generated index.d.ts with skipLibCheck disabled. This catches undefined
type references that would otherwise slip through since the base
tsconfig has skipLibCheck enabled.

https://claude.ai/code/session_01HRaZd7KV54jKh3BFr2ZdKu
@AgentEnder AgentEnder force-pushed the claude/fix-nx-32205-g9LY6 branch from 05a7ac9 to efc08e0 Compare April 10, 2026 16:27
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

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

✅ The fix from Nx Cloud was applied

We add a .gitignore negation exception for packages/nx/src/native/dts-header.d.ts to fix the no-ignored-tracked-files conformance violation. The existing packages/nx/**/*.d.ts pattern was catching this newly introduced hand-authored header file, causing Nx hashing issues. This follows the same pattern already in place for index.d.ts and other intentionally tracked .d.ts files.

Tip

We verified this fix by re-running nx-cloud record -- pnpm nx conformance:check.

Suggested Fix changes
diff --git a/.gitignore b/.gitignore
index 0312763e..3ac18d26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -152,5 +152,6 @@ packages/nx/**/*.d.ts
 !packages/nx/src/utils/perf-hooks.d.ts
 !packages/nx/src/ai/set-up-ai-agents/schema.d.ts
 !packages/nx/src/native/index.d.ts
+!packages/nx/src/native/dts-header.d.ts
 e2e/**/*.d.ts
 e2e/**/*.d.ts.map

Note

Auto-apply was skipped. The previous CI pipeline execution was triggered by Nx Cloud

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.

Revert fix via Nx Cloud  

View interactive diff ↗

➡️ This fix was applied by Craigory Coppola

🎓 Learn more about Self-Healing CI on nx.dev

Co-authored-by: AgentEnder <AgentEnder@users.noreply.github.com>
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.

2 participants