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

type inference? #3

Open
cancerberoSgx opened this issue May 23, 2019 · 1 comment
Open

type inference? #3

cancerberoSgx opened this issue May 23, 2019 · 1 comment

Comments

@cancerberoSgx
Copy link

I'm not seeing the tool to infer types form usage.. And IMO this should be the basic feature for a tool like this. I see you have focused more on code tranpilation like class declaration synyax, I think the most important part is being able to add acceptable types to variables , parameters, return types, etc (and not just add "any" to everything. So I wanted to give you a tip:

Fortunately the compiler language service is capable of inferring times for most of variables, parameters, etc. I found out it has LOTS of code-fixes that you can apply programatically. These are some examples (using ts-morph) library which provides an higher API, but it's also accomplished with compiler API directly:

This is a typescript-plugin that applies / suggests all codefixes available in the file tying suggestions in all ranges:
https://github.com/cancerberoSgx/typescript-plugins-of-mine/blob/master/typescript-plugin-all-ts-fixes-and-refactors/src/supportedCodeFixes.ts

You might find interesting this snippet that prints all code-fixes and refactors codes, names and descriptions:

https://github.com/cancerberoSgx/typescript-plugins-of-mine/blob/master/typescript-plugin-all-ts-fixes-and-refactors/src/supportedCodeFixes.ts

This one has a inferTypesFromUsage() function that is what I just suggested to add in your lib:

convert require to import:

these is a test that runs the for remove all unused variables ode fix:

Hope it helps! feel free to use the library or code. thanks! keep ip up!

@gregjacobs
Copy link
Owner

An awesome idea. Wish I had any time to implement this 😂 PRs welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants