microsoft / microsoft/ts-fix

Enable `import` autofix?

Open
#31 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
232
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read src/index.ts at lines 260-262 and trace how the -f CLI option selects autofixes. Confirm that explicitly passing -f import enables the import autofix while leaving it disabled by default, including for inline type imports such as import('some/module').Foo.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.