Skip to content

fix(cli): generate proxy .d.ts files for TypeScript compilerOptions.types resolution#1165

Closed
ryoppippi wants to merge 1 commit intovoidzero-dev:mainfrom
ryoppippi:fix/tsconfig-types-resolution
Closed

fix(cli): generate proxy .d.ts files for TypeScript compilerOptions.types resolution#1165
ryoppippi wants to merge 1 commit intovoidzero-dev:mainfrom
ryoppippi:fix/tsconfig-types-resolution

Conversation

@ryoppippi
Copy link
Copy Markdown

Problem

TypeScript's compilerOptions.types field resolves package subpaths via the filesystem directly, without consulting package.json exports. This means:

// tsconfig.json
{ "compilerOptions": { "types": ["vite-plus/test/globals"] } }

...causes TypeScript to look for node_modules/vite-plus/test/globals.d.ts on disk. That file didn't exist — the actual shim was at dist/test/globals.d.ts, only reachable via the exports map.

This is why vitest/globals works: vitest places globals.d.ts at the package root, matching exactly what TypeScript expects.

Fix

syncTestPackageExports() now also generates proxy .d.ts files at test/{name}.d.ts for type-only exports (those with only a types field and no runtime JS). Each proxy contains a triple-slash reference:

/// <reference types="@voidzero-dev/vite-plus-test/globals" />

Triple-slash reference types directives do go through the exports field, so this correctly delegates to the underlying package while being discoverable at the filesystem path TypeScript expects for compilerOptions.types.

The generated test/ directory is gitignored and added to package.json files at build time so it is included in published packages.

…ypes resolution

TypeScript's compilerOptions.types field resolves package subpaths via the
filesystem directly, without consulting package.json exports. This means
"types": ["vite-plus/test/globals"] looks for node_modules/vite-plus/test/globals.d.ts
on disk, but that file didn't exist — the actual shim was at dist/test/globals.d.ts,
only reachable via the exports map.

vitest works because it places globals.d.ts at the package root, matching the
filesystem path TypeScript expects.

Fix: syncTestPackageExports() now also generates proxy .d.ts files at test/{name}.d.ts
for type-only exports (those with only a "types" field and no runtime JS). Each proxy
contains a triple-slash reference directive:
  /// <reference types="@voidzero-dev/vite-plus-test/globals" />

Triple-slash reference types directives DO go through the exports field, so this
correctly delegates to the underlying package while being discoverable at the path
TypeScript expects for compilerOptions.types.

The generated test/ directory is gitignored and added to package.json files at
build time, so it is included in published packages.
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 27, 2026

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit d476f5d
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/69c63c2e8b67320008dd248b

@ryoppippi
Copy link
Copy Markdown
Author

oh! how can i fix ci? i have no idea

@kazupon
Copy link
Copy Markdown
Collaborator

kazupon commented Mar 27, 2026

@ryoppippi
You can metion with at codex

@kazupon
Copy link
Copy Markdown
Collaborator

kazupon commented Mar 27, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ryoppippi
Copy link
Copy Markdown
Author

@codex fix ci errror

@chatgpt-codex-connector
Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

@ryoppippi
Copy link
Copy Markdown
Author

wtf!?

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Mar 27, 2026

@ryoppippi Do you have a code repository that can reproduce this issue? Could you provide it? I can add it to the ecosystem-ci as a continuous e2e test case.

@ryoppippi
Copy link
Copy Markdown
Author

ryoppippi commented Mar 27, 2026

@fengmk2 hey! here is the repro!
https://github.com/ryoppippi/vite-plus-vitest-global-type-minimal-repro/

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Mar 27, 2026

@ryoppippi Let me follow up on this issue, I need to make some changes to the current packages/test/BUNDLING.md.

@fengmk2 fengmk2 self-assigned this Mar 27, 2026
@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Mar 28, 2026

move to #1177

@fengmk2 fengmk2 closed this Mar 28, 2026
@ryoppippi
Copy link
Copy Markdown
Author

thank you

@ryoppippi ryoppippi deleted the fix/tsconfig-types-resolution branch March 28, 2026 12:36
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.

3 participants