Skip to content

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

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

Closed
tetsuharuohzeki opened this issue Feb 22, 2020 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@tetsuharuohzeki
Copy link
Contributor

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:

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Feb 26, 2020
@RyanCavanaugh
Copy link
Member

This is the intended behavior. The intent of the flag is to tell you about import declarations that would "go missing" during type-only elision (thus potentially changing runtime behavior), not to tell you about clauses that would be removed (which have no effect).

@typescript-bot
Copy link
Collaborator

This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants