Need TypeScript/Node Preserve Import Order Directive for Optimize Imports

Answered

I have the following fragment of code.

Import ". /models/Users"; // Import this first
import "./config/passport"; // Import this 2nd
import routes = require("./routes");

These are dependent of each other and must be executed in the order but when the Optimize Import option is in effect in the "Commit Changes" dialog box, it

will rearrange the imports to;

import routes = require("./routes");
Import ". /models/Users"; // Import this first
import "./config/passport"; // Import this 2nd

And breaks the code.

Reason Why This is Not Great Right Now

  • I do like to use Optimize Imports. In fact, I check all of the boxes on my code-complete commit including Reformat Code all the way to Cleanup and even Update Copyright. Now I cannot use them.
  • Right now, I remember not to use this feature but when this is handed off to other developers, they will forget it, I might forget it too a year from now, and it will suddenly break the code requiring a debug session.

What I Wish I Had

Can we have a IDE directive to disable the arrangement in the parts where I don't want it? Like....

// PreserveOrder or // DisableImportoptimization

specific to the file or section of the code.

Can you do this?

Any other workarounds? Granted this is likely a bad coding practice, as professionals, we need to get around immediate issues possibly caused by others to keep the product going. 

1 comment
Comment actions Permalink
Official comment

Hello,

Please vote for the following feature request: https://youtrack.jetbrains.com/issue/IDEA-24849 .

Please sign in to leave a comment.