Skip to content
New issue

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

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

Already on GitHub? # to your account

Add codefix to generate types for untyped module #26588

Merged
4 commits merged into from
Sep 18, 2018
Merged

Add codefix to generate types for untyped module #26588

4 commits merged into from
Sep 18, 2018

Conversation

ghost
Copy link

@ghost ghost commented Aug 21, 2018

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 fix requires 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 in typingsInstaller since that's currently our only separate process, and I didn't want to create a third process.
typingsInstaller uses inspectValue.ts, which is designed to not require TypeScript (and not pull more code into typingsInstaller such as textChanges), and just produce a JSON representation of the required value. That is then passed to generateTypes.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.

@ghost ghost force-pushed the dtsgen branch 6 times, most recently from 2ec6cdf to 1429bc1 Compare August 22, 2018 18:49
@ghost ghost requested review from amcasey and sheetalkamat August 22, 2018 18:50
@ghost ghost force-pushed the dtsgen branch 2 times, most recently from 8847ebf to eda8c5a Compare August 22, 2018 23:16
This pull request was closed.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use dtsGen to generate declaration files for imported modules with no declarations
1 participant