Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: organize-imports strips type imports that only appear in satisfies right-hand side in typescript project #256

Open
thetos7 opened this issue Jul 27, 2023 · 2 comments

Comments

@thetos7
Copy link

thetos7 commented Jul 27, 2023

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);
@lmexo
Copy link

lmexo commented Aug 3, 2023

Should be fixed by bumping ts-morph to the current version. @thorn0 Is the project still alive?

@jakkn
Copy link

jakkn commented Apr 16, 2024

I worked around this error with yarn resolutions (overrides for npm). But a new release would be good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants