Skip to content

fix(dts): add .json fallback for json extension substitution#1052

Merged
Boshen merged 1 commit into
fix/dts-typesversions-prefixfrom
fix/dts-json-fallback
Mar 5, 2026
Merged

fix(dts): add .json fallback for json extension substitution#1052
Boshen merged 1 commit into
fix/dts-typesversions-prefixfrom
fix/dts-json-fallback

Conversation

@Boshen

@Boshen Boshen commented Mar 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Match TypeScript's tryAddingExtensions behavior for .json imports: after trying .d.json.ts, also try the .json extension itself
  • Without this, import "./data.json" would only find ./data.d.json.ts and miss the actual ./data.json file
  • TS reference: extensions & Extensions.Json && tryExtension(Extension.Json)

Stacked on #1051.

🤖 Generated with Claude Code

@Boshen Boshen force-pushed the fix/dts-json-fallback branch from 44b354b to 21a407f Compare March 5, 2026 14:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8641fd368b

ℹ️ 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".

Comment thread src/dts_resolver.rs
Match TypeScript's `tryAddingExtensions` behavior for `.json` imports:
after trying `.d.json.ts`, also try the `.json` extension itself. Without
this, `import "./data.json"` would only find `./data.d.json.ts` and miss
the actual `./data.json` file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Boshen Boshen force-pushed the fix/dts-typesversions-prefix branch from 6b28554 to 8653df8 Compare March 5, 2026 14:35
@Boshen Boshen force-pushed the fix/dts-json-fallback branch from 21a407f to b9e95cb Compare March 5, 2026 14:36
@Boshen Boshen merged commit c97d898 into fix/dts-typesversions-prefix Mar 5, 2026
12 checks passed
@Boshen Boshen deleted the fix/dts-json-fallback branch March 5, 2026 14:36
@codecov

codecov Bot commented Mar 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (fix/dts-typesversions-prefix@8653df8). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/dts_resolver.rs 25.00% 3 Missing ⚠️
Additional details and impacted files
@@                       Coverage Diff                       @@
##             fix/dts-typesversions-prefix    #1052   +/-   ##
===============================================================
  Coverage                                ?   91.74%           
===============================================================
  Files                                   ?       20           
  Lines                                   ?     3987           
  Branches                                ?        0           
===============================================================
  Hits                                    ?     3658           
  Misses                                  ?      329           
  Partials                                ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9e95cb594

ℹ️ 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".

Comment thread src/dts_resolver.rs
return Some(p);
}
// TS: `extensions & Extensions.Json && tryExtension(Extension.Json)`
if let Some(p) = self.dts_try_file(base, ".json", ctx) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard .json fallback by active extension set

This unconditional .json probe runs even when the caller intentionally excludes runtime files (for example the first node_modules pass uses priority_exts = TYPESCRIPT|DECLARATION in dts_resolve_node_modules). In that path, a package whose main points to index.json now resolves to the JSON implementation before the resolver gets to the @types lookup, which regresses declaration-priority behavior and can return runtime JSON where typings are available.

Useful? React with 👍 / 👎.

@codspeed-hq

codspeed-hq Bot commented Mar 5, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.02%

⚡ 1 improved benchmark
✅ 12 untouched benchmarks
⏩ 5 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
resolver_real[multi-thread] 474.5 µs 456.2 µs +4.02%

Comparing fix/dts-json-fallback (b9e95cb) with main (8deef34)2

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on fix/dts-typesversions-prefix (8653df8) during the generation of this report, so main (8deef34) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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.

1 participant