microsoft / ts-fix

CLI for applying TypeScript codefixes
MIT License
111 stars 10 forks source link

Enable `import` autofix? #31

Open MichaelMitchell-at opened 4 months ago

MichaelMitchell-at commented 4 months ago

I noticed that the import autofix is disabled here https://github.com/microsoft/ts-fix/blob/2898fac87de321fe5d455b594f874bbcafbab6bd/src/index.ts#L260-L262

I can maybe see why it's disabled by default, but it would be nice to at least be able to use it if -f import is explicitly provided on the CLI. One use case is that the autofixer for isolatedDeclarations sometimes adds type annotations using inline imports, e.g.

const foo: import('some/module').Foo = ...;

which is not our, and probably not many others', preferred style.

So what I'll do is use a regular expression to just remove all the import('...'). parts, but then now I need to add top-level imports for a bunch of types. This is where the import autofix comes in clutch. I commented out that line above in ts-fix and ran the autofixer and it pretty much worked flawlessly.

Just wanted to provide a data point, but feel free to close if not likely to be implemented.