Closed
Description
TypeScript Version: 3.8.2
Search Terms:
tsc with importsNotUsedAsValues=error
does not error that mixing type and actual variables in same import statement (e.g. import { TypeName, ActualVariable } from '.....';
)
Code
Set options is importsNotUsedAsValues=error
// bar.ts
export class Bar {};
export function getBar(): Bar {
return new Bar();
}
// main.ts
import { Bar, getBar } from './bar';
const a: Bar = getBar();
console.log(a);
Expected behavior:
- In main.ts,
import { Bar, getBar } from './bar';
should be error becauseBar
is used only as type. tsc should suggest to split into 2 line like:
import type { Bar, } from './bar';
import { getBar } from './bar';
Actual behavior:
In main.ts, tsc does not cause error about using import type {} from ...
.
If we change main.ts to the following, tsc make it error correctly.
// main.ts
import { Bar } from './bar'; // By tsc: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.ts(1371)`
import { getBar } from './bar';
const a: Bar = getBar();
console.log(a);
Playground Link:
I'm sorry. I could not find a way to create this snippet in TypeScript PlayGround.
Related Issues: