-
Notifications
You must be signed in to change notification settings - Fork 889
no-duplicate-imports false positive with namespace imports #3418
Comments
Another use case might be importing symbols of the same name from different packages: import * as fooApi from "api/foo";
import { FooContext } from "api/foo";
import * as barApi from "api/bar";
const c: FooContext = {};
fooApi.doStuff(c);
barApi.doStuff(); |
Yeah, hit this error few months back and now again. The error message |
Another use case is when importing modules for side effects:
The consideration here is that when the TypeScript compiler imports disappearing types only from a module (e.g., interfaces, type aliases, enum declarations, etc.), then the import of that module disappears. As a result, side-effects-only imports sometimes have to be emitted as well. |
@robpaveza If I were coming to your codebase fresh, I'd love to see that called out explicitly: import {IFoo, IFooType} from './foo';
// tslint:disable-next-line:no-duplicate-any: Also import the side-effects
import "./foo"; |
I got this linting error on the following snippet from firebase documentation:
|
Fixed by #4524! ✨ |
Bug Report
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
Expected behavior
For the rule to ignore, at least through an option, this specific case of combining namespace imports with named imports.
While default imports can be combined with named imports (
import Foo, { Bar } from 'foobar'
), it's not possible to combine them with namespace imports other than changing all references to refer to the namespace instead.It is sometimes useful to import certain names of a namespace for commonly used things like types, while still accessing the less commonly used exports through the namespace object.
The text was updated successfully, but these errors were encountered: