organize-imports-cli
organize-imports-cli copied to clipboard
Bug report: `organize-imports` strips type imports that only appear in `satisfies` right-hand side in typescript project
I have noticed this issue recently in projects.
In TypeScript files, whenever a type from a different module is exclusively used in satsifies
type assertions, the organize-imports
CLI strips the type from the import, resulting in the file having compilation errors.
Example
types.ts
export type Content = {
text: string;
};
export const buildContent = (arg: Content) => {
// implementation
};
main.ts
import { Content, buildContent } from "./types";
buildContent({
text: "my text"
} satisfies Content);
When running organize-imports
, I would expect main.ts
to remain the same, however the output ends up being:
import { buildContent } from "./types";
buildContent({
text: "my text"
} satisfies Content); // ERROR: Content is not defined!
Which is a compile-time error because of the missing type identifier.
Workaround
I do have a workaround for now, by referencing the type in a type alias:
import { Content, buildContent } from "./types";
type __Keep = Content;
buildContent({
text: "my text"
} satisfies Content);
Should be fixed by bumping ts-morph to the current version. @thorn0 Is the project still alive?
I worked around this error with yarn resolutions (overrides for npm). But a new release would be good 👍