Skip to content

Fix porting bug in resolveAutomaticTypeDirectives#2562

Merged
jakebailey merged 2 commits intomainfrom
jabaile/fix-2418
Jan 22, 2026
Merged

Fix porting bug in resolveAutomaticTypeDirectives#2562
jakebailey merged 2 commits intomainfrom
jabaile/fix-2418

Conversation

@jakebailey
Copy link
Member

@jakebailey jakebailey commented Jan 21, 2026

Fixes #2418

The original TS says:

for (let i = 0; i < automaticTypeDirectiveNames.length; i++) {
    // under node16/nodenext module resolution, load `types`/ata include names as cjs resolution results by passing an `undefined` mode
    automaticTypeDirectiveResolutions.set(automaticTypeDirectiveNames[i], /*mode*/ undefined, resolutions[i]);
    processTypeReferenceDirective(
        automaticTypeDirectiveNames[i],
        /*mode*/ undefined,
        resolutions[i],
        {
            kind: FileIncludeKind.AutomaticTypeDirectiveFile,
            typeReference: automaticTypeDirectiveNames[i],
            packageId: resolutions[i]?.resolvedTypeReferenceDirective?.packageId,
        },
    );
}

Our version of undefined mode is ResolutionModeNone.

This test is goofy, but the best I could come up with to show that there's a difference (check the second commit)

For #2418, #2361 actually fixed most of the issues. This fixes the rest, except for:

1718,1720d1717
< /home/jabaile/work/repros/tsgo2418/Paideia/node_modules/@payloadcms/db-postgres/node_modules/drizzle-orm/index.d.ts
< /home/jabaile/work/repros/tsgo2418/Paideia/node_modules/@payloadcms/db-postgres/node_modules/drizzle-orm/node-postgres/index.d.ts
< /home/jabaile/work/repros/tsgo2418/Paideia/node_modules/@payloadcms/db-postgres/node_modules/drizzle-orm/pg-core/index.d.ts

And these are three cases of deduplicated files that tsc did not properly deduplicate (but my PR seemingly does), a case I believe Sheetal noted.

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

This PR fixes a porting bug in resolveAutomaticTypeDirectives where the wrong resolution mode was being used. The original TypeScript code passes undefined as the mode parameter, which should translate to ResolutionModeNone in Go, but the port incorrectly used ModuleKindNodeNext.

Changes:

  • Fixed the resolution mode for automatic type directives from ModuleKindNodeNext to ResolutionModeNone
  • Added explanatory comments describing the behavior for both node16/nodenext and bundler module resolution
  • Added a comprehensive test case to verify the fix works correctly with bundler module resolution

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
internal/compiler/fileloader.go Corrected the resolution mode from ModuleKindNodeNext to ResolutionModeNone and added explanatory comments
testdata/tests/cases/compiler/automaticTypeDirectiveResolutionBundler.ts New test demonstrating that automatic type directives resolve with the correct condition under bundler resolution
testdata/baselines/reference/compiler/automaticTypeDirectiveResolutionBundler.types Expected type baseline showing correct resolution to esm.d.mts
testdata/baselines/reference/compiler/automaticTypeDirectiveResolutionBundler.trace.json Trace baseline confirming the 'import' condition is matched during resolution
testdata/baselines/reference/compiler/automaticTypeDirectiveResolutionBundler.symbols Symbol baseline showing correct symbol resolution

Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

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

This seems good but why didn't it delete any diffs?

@jakebailey
Copy link
Member Author

I'm not sure. The relationship between ResolutionMode and ModuleKind means we are seemingly potentially missing some cases, so I can't even replicate this problem in Strada...

@jakebailey jakebailey added this pull request to the merge queue Jan 22, 2026
Merged via the queue into main with commit 461f629 Jan 22, 2026
28 checks passed
@jakebailey jakebailey deleted the jabaile/fix-2418 branch January 22, 2026 19:25
@jakebailey
Copy link
Member Author

Forcing this into Strada with casts nets these two failures:

  98866 passing (2m)
  2 failing

  1) 
       
         unittests:: reuseProgramStructure:: General
           fails if change affects type references:
     Error: New baseline created at tests/baselines/local/reuseProgramStructure/change-affects-type-references.js
      at writeComparison (src/harness/harnessIO.ts:1546:27)
      at Object.runBaseline2 [as runBaseline] (src/harness/harnessIO.ts:1565:9)
      at runBaseline (src/testRunner/unittests/reuseProgramStructure.ts:80:26)
      at Context.<anonymous> (src/testRunner/unittests/reuseProgramStructure.ts:154:9)
      at processImmediate (node:internal/timers:504:21)

  2) 
       
         unittests:: reuseProgramStructure:: General
           succeeds if change doesn't affect type references:
     Error: New baseline created at tests/baselines/local/reuseProgramStructure/change-doesnot-affect-type-references.js
      at writeComparison (src/harness/harnessIO.ts:1546:27)
      at Object.runBaseline2 [as runBaseline] (src/harness/harnessIO.ts:1565:9)
      at runBaseline (src/testRunner/unittests/reuseProgramStructure.ts:80:26)
      at Context.<anonymous> (src/testRunner/unittests/reuseProgramStructure.ts:163:9)
      at processImmediate (node:internal/timers:504:21)

So we don't actually have any tests for this. Yay!

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.

[BUG] tsgo list more files than tsc

3 participants