Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler API: respect typeRoots in resolveModuleName #44270

Closed
5 tasks done
idan-at opened this issue May 26, 2021 · 2 comments Β· Fixed by #51715
Closed
5 tasks done

Compiler API: respect typeRoots in resolveModuleName #44270

idan-at opened this issue May 26, 2021 · 2 comments Β· Fixed by #51715
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@idan-at
Copy link

idan-at commented May 26, 2021

Suggestion

πŸ” Search Terms

List of keywords you searched for before creating this issue: I've tried resolveModuleName, typeRoot, api and their combinations.

βœ… Viability Checklist

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

At the Compiler API Wiki, You can see that resolveModuleNames suggested implementation treats node modules packages typings and custom typings differently (here).

This means anyone that uses the ts.resolveModuleName API has to implement the fallback and search on moduleSearchLocations (which I assume, we'll get those by reading the tsconfig and scanning for the typeRoot.

I am not sure whether this is a bug or not, but I would assume ts.resolveModuleName would respect the typeRoots given in the passed compiler options. What do you think? Is there a reason it doesn't behave this way?

NOTE: I've not just relied on the example, I've tested it myself.

πŸ’» Use Cases

Any tool that uses the compiler API will need this, for example, I'm writing an ESLint plugin that makes sure every dependency either comes with type declarations or it has the corresponding @types package installed next to it. (It's here)

Thanks!

@sheetalkamat
Copy link
Member

Is this related to #37958 and to be handled in #39708 ?

@idan-at
Copy link
Author

idan-at commented May 27, 2021

Yup, it's related, missed that one.

Thanks for working on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
3 participants