Skip to content

Conversation

sheetalkamat
Copy link
Member

During tsc -b the resolutions are shared across projects if the setting match. This means that if you resolved your own package name before building the project, you will get the "input" file as the resolution. And when we go to project that references this package and config, the input file will be used as resolution. This normally works out because we have rule to redirect to d.ts file and report error. But the issue is that if the input file is js file, it has rules for eliding imports. So if the file is input file name from referenced project, treat it as d.ts file for purpose of deciding eliding of imports and whether to include file or not.

Fixes #57652

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Apr 24, 2024
@sheetalkamat sheetalkamat changed the title Resolution repro Treat the input file name from referenced project as "ts" rather than file extension it is when determining eliding file for program construction Apr 24, 2024
const isFromNodeModulesSearch = resolution.isExternalLibraryImport;
const isJsFile = !resolutionExtensionIsTSOrJson(resolution.extension);
// If this is js file source of project reference, dont treat it as js file but as d.ts
const isJsFile = !resolutionExtensionIsTSOrJson(resolution.extension) && !getProjectReferenceRedirectProject(resolution.resolvedFileName);
Copy link
Member

Choose a reason for hiding this comment

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

I feel like I don't quite understand how this works; "is JS" seems like it should just be "has the JS extension", but this would say that if it came from a referenced project, we don't treat it as such? So, won't we misinterpret later checks regarding node module checks?

Is it the case that an equivalent fix would just be calling getProjectReferenceRedirectProject below in the shouldAddFile checks?

Copy link
Member Author

Choose a reason for hiding this comment

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

for all purposes we will be adding ".d.ts" file so we are treating it as such. That happens in findSourceFile where we map the "original file name" to output "d.ts" file name

@sheetalkamat sheetalkamat merged commit 95d23ca into main Apr 26, 2024
@sheetalkamat sheetalkamat deleted the resolutionRepro branch April 26, 2024 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript fails to resolve dependency in monorepo given specific conditions
3 participants