isolatedDeclarations fixer inserts unnecessary inline imports #60266
Labels
Experience Enhancement
Noncontroversial enhancements
Help Wanted
You can do this
Suggestion
An idea for TypeScript
Milestone
🔎 Search Terms
isolatedDeclarations autofix fix imports
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about isolated declarations. (It seems to go back to the original commits that created the infer-return-type fixers.)
⏯ Playground Link
https://github.com/benjaminjkraft/typescript-autofix-import-bug
💻 Code
🙁 Actual behavior
Isolated declarations reports an error for
g()
(correct). But the fix is to add: { wrapper: import("./callee").T }
, which is correct but needlessly unreadable.🙂 Expected behavior
Instead, the fix should add
: { wrapper: T }
, and then an appropriate import.Additional information about the issue
I think the fix may just be to remove the
if
here? That seems to work in my local testing, although I haven't tested very exhaustively.I suspect this applies in a few other places (e.g. other calls into the same code with the same pattern), but I didn't look very closely. It also applies to a number of other patterns where you return something exported from elsewhere; this was just the most convenient example to explain.
I may be able to contribute a fix for this (at least once my company reviews the CLA).
The text was updated successfully, but these errors were encountered: