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

Typescript ignore "import types" #443

Open
danikaze opened this issue Dec 14, 2024 · 1 comment
Open

Typescript ignore "import types" #443

danikaze opened this issue Dec 14, 2024 · 1 comment

Comments

@danikaze
Copy link

This is related to this issue.

Specifying

detectiveOptions: {
  ts: {
    skipTypeImports: true,
  }
}

works only for this kind of code

import type { TypeName } from 'path';

but TS is clever enough to auto-detect types (as they don't generate any output on the JS), so this

import { TypeName } from 'path'; // no "type" keyword

should work the same, when TypeName is a type, an interface, a const enum or anything that doesn't generate anything in memory.

In summary, skipTypeImports should work not when there's a import type, but also based on the nature of the imported property as well when there's a basic import.

@danikaze
Copy link
Author

I was checking the code of how detective-typescript works, and saw that it only sees one file at a time without knowing what's importing. That makes a bit hard detecting if an export is a type-like declaration or a real object.

My recommendation so far would be to recursively get into what the imported file is exporting and check their types. Keep a cache of AST objects to avoid parsing the same file multiple times...

This "easy" feature requires a somehow complex solution.
Any thoughts?

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

1 participant