False positives on types imported with `import type`
See original GitHub issueIt’s possible that this is an issue with ts-morph, but wanted to report this here. The new import type syntax introduced in TypeScript 3.8 appears to be resulting in false positives. Here’s an example (applying this patch on this repo @ https://github.com/nadeesha/ts-prune/commit/e879ac6e4d29e64fea872205a8d7c37e19256b22):
diff --git a/src/analyzer.ts b/src/analyzer.ts
index d767698..726f3ba 100644
--- a/src/analyzer.ts
+++ b/src/analyzer.ts
@@ -8,6 +8,7 @@ import {
} from "ts-morph";
import { isDefinitelyUsedImport } from "./util/isDefinitelyUsedImport";
import { getModuleSourceFile } from "./util/getModuleSourceFile";
+import type { SomeType } from "./presenter";
type OnResultType = (result: IAnalysedResult) => void;
@@ -22,7 +23,7 @@ export interface IAnalysedResult {
symbols: Array<string>;
}
-function handleExportDeclaration(node: SourceFileReferencingNodes) {
+function handleExportDeclaration(node: SourceFileReferencingNodes, _someParam?: SomeType) {
return (node as ExportDeclaration).getNamedExports().map(n => n.getName());
}
diff --git a/src/presenter.ts b/src/presenter.ts
index dcf1320..2115e1e 100644
--- a/src/presenter.ts
+++ b/src/presenter.ts
@@ -15,3 +15,5 @@ export const present = (state: State) => {
return [].concat.apply([], unused2D) as Array<IAnalysedResult>;
};
+
+export type SomeType = any;
This results in:
➜ ts-prune git:(master) ✗ ts-prune
SomeType @ ./src/presenter.ts
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
[no-duplicate-imports] false positive rule on "import type" #2315
Repro import type { Foo } from './foo' import { foo } from './foo' reports eslint(no-duplicated-imports) error.
Read more >JavaScript/TypeScript false positive with absolute imports
Importing a module that is not declared as a dependency makes it an implicit one and is bound to create problems.
Read more >Typescript + Eslint false positive for imports + `declare global`
1 Answer 1 ... Turn off "no-undef": "off"(disallow the use of undeclared variables unless mentioned in /*global */ comments) and to be handled...
Read more >Common issues and solutions - mypy 0.991 documentation
ImportError from circular imports. NameError: name "X" is not defined from forward references. TypeError: 'type' object is not subscriptable from types that ...
Read more >Invalid 'unused import' highlighting in TypeScript when using ...
... compiler needs to generate the type declarations, so needs the types it uses to be imported. This can lead to false positives...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I couldn’t reproduce this is node 12 btw. Maybe something else is at play here. Anyways, thanks for reporting!
@nadeesha
import typeis supported by @babel/core 6.9.0 and newer current version is 7.1.1