Add codefix to generate types for untyped module #26588
Merged
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 #25746
Adds a new codefix, also in
fixCannotFindModule.ts
since it is similar to the fix for installing an@types
package and won't trigger if an@types
package exists. This fixrequire
s the value of the module and inspects the resulting value.We don't want to call
require
(which can execute arbitrary code) during regular code fixes, so instead we generate a command which can be executed in a separate process. I put this intypingsInstaller
since that's currently our only separate process, and I didn't want to create a third process.typingsInstaller
usesinspectValue.ts
, which is designed to not require TypeScript (and not pull more code intotypingsInstaller
such astextChanges
), and just produce a JSON representation of the required value. That is then passed togenerateTypes.ts
which actually converts that to an AST and renders.The function
generateTypesForModule
is currently internal, but could be publicly exposed and made to be the implementation of dts-gen, which its code is based on.