Skip to content

Comments

Improve CommonJS support#2893

Open
ahejlsberg wants to merge 2 commits intomainfrom
cjs-module-exports
Open

Improve CommonJS support#2893
ahejlsberg wants to merge 2 commits intomainfrom
cjs-module-exports

Conversation

@ahejlsberg
Copy link
Member

In this PR:

  • Permit multiple module.exports assignments in a file and union the assigned types.
  • Make JSDoc @typedef declarations available on imports of CJS modules that use module.exports.
  • Exclude module.exports assignments from stricter checking of TypeScript export = declarations.

These changes align Corsa more closely with the current behavior in Strada and eliminate a large number of baseline differences.

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 improves CommonJS support in the TypeScript compiler port by making three key changes:

  1. Permitting multiple module.exports assignments and unioning their types
  2. Making JSDoc @typedef declarations available on imports of CJS modules with module.exports
  3. Excluding module.exports assignments from stricter TypeScript export = checking

These changes align Corsa more closely with Strada's behavior and eliminate numerous baseline differences.

Changes:

  • Added mergedExportEquals field to ModuleSymbolLinks to track merged export types for CJS modules
  • Updated test baselines to reflect removal of TS1203 errors for module.exports assignments
  • Improved type resolution for CJS modules with multiple exports and typedefs

Reviewed changes

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

Show a summary per file
File Description
internal/checker/types.go Added mergedExportEquals field to support merging multiple CJS exports
testdata/baselines/reference/submodule/**/*.diff Removed TS1203 "Export assignment cannot be used when targeting ECMAScript modules" errors for module.exports
testdata/baselines/reference/submodule/**/*.types Updated type information to show proper CJS module export types
testdata/baselines/reference/submodule/**/*.symbols Updated symbol resolution for CJS exports
testdata/baselines/reference/conformance/**/*.errors.txt Removed erroneous TS1203 errors from conformance tests

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