Fix: Respect allowSyntheticDefaultImports for export specifiers from declaration files #62758
+7
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #XXXXX
Problem
allowSyntheticDefaultImports(defaults totrue) was not respected when re-exporting defaults from declaration files withexport { default as Foo } from "./b"syntax. The compiler incorrectly reported "Module has no exported member 'default'" errors even when the option was enabled and the target was a declaration file.The rationale is that declaration files may correspond to CommonJS modules at runtime, where a default import is allowed to reference the whole
module.exportssymbol.Changes
Modified
getTargetofModuleDefaultinchecker.tsto allow synthetic defaults for export specifiers when targeting declaration files:ExportSpecifiernodeallowSyntheticDefaultImportsis enabled AND the target is a declaration file (!file || file.isDeclarationFile), sethasSyntheticDefault = trueThe fix correctly handles the ambiguity of declaration files which may represent either ESM or CommonJS modules at runtime.
Test Updates
No error baseline changes needed. The fix correctly allows:
reexportMissingDefault4.ts-export { default } from "./b.d.ts"✓reexportMissingDefault5.ts-export { default as Foo } from "./b.d.ts"✓Tests targeting TypeScript source files (
.ts) correctly maintain their errors as expected.Original prompt
export { default as Foo } from "./b"#62757💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.