Skip to content

tsc does not error mixing type and actual variable in same import statement on importsNotUsedAsValues=error #36959

Closed
@tetsuharuohzeki

Description

@tetsuharuohzeki

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 because Bar 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions