Skip to content

Commit d7ac3ad

Browse files
Copilotandrewbranch
andcommitted
Use ES module range check and try both redirect mappings
Co-authored-by: andrewbranch <[email protected]>
1 parent 0d532eb commit d7ac3ad

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3797,12 +3797,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
37973797
// For other files (not node16/nodenext with impliedNodeFormat), check if we can determine
37983798
// the module format from project references
37993799
if (!targetMode && file.isDeclarationFile) {
3800-
const redirect = host.getRedirectFromSourceFile(file.path);
3800+
// Try to get the project reference - try both source file mapping and output file mapping
3801+
// since declaration files can be mapped either way depending on how they're resolved
3802+
const redirect = host.getRedirectFromSourceFile(file.path) || host.getRedirectFromOutput(file.path);
38013803
if (redirect) {
38023804
// This is a declaration file from a project reference, so we can determine
38033805
// its module format from the referenced project's options
38043806
const targetModuleKind = host.getEmitModuleFormatOfFile(file);
3805-
if (usageMode === ModuleKind.ESNext && targetModuleKind >= ModuleKind.ES2015) {
3807+
if (usageMode === ModuleKind.ESNext && ModuleKind.ES2015 <= targetModuleKind && targetModuleKind <= ModuleKind.ESNext) {
38063808
return false;
38073809
}
38083810
}

0 commit comments

Comments
 (0)