Skip to content
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

'const enum' conflict with 'importsNotUsedAsValue'' #36003

Closed
ajafff opened this issue Jan 4, 2020 · 4 comments · Fixed by #36092
Closed

'const enum' conflict with 'importsNotUsedAsValue'' #36003

ajafff opened this issue Jan 4, 2020 · 4 comments · Fixed by #36092
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ajafff
Copy link
Contributor

ajafff commented Jan 4, 2020

TypeScript Version: 3.8.0-dev.20200104

Search Terms:

Code

// @importsNotUsedAsValue: true

// @filename: a.ts
export const enum E {
  One,
  Two,
}

// @filename: b.ts
import type {E} from './a';

export let v = E.One;

Expected behavior:

No error.

Actual behavior:

Type-only import causes Enum 'E' cannot be used as a value because only its type has been imported.ts(1362)
Since importing const enums at runtime is not necessary due to inlining, they should be allowed to be used with type-only import.

If I use a regular import, I get This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValue' is set to 'error'.ts(1371)

Related Issues: Introduced by @andrewbranch in #35200

@ajafff
Copy link
Contributor Author

ajafff commented Jan 4, 2020

Also note that the type-only import of the const enum is reported as unused.

@andrewbranch
Copy link
Member

I see the motivation, but import type means more than just “don’t emit this import declaration.” It filters the symbol meanings down to just type and type-containing namespace meanings. We’re currently discussing a similar scenario:

import type { BaseClass } from './a'
declare class C extends BaseClass {} // Should this be treated as having a value?

and the instincts on the team are mixed. But using a type-only import in the right-hand side of an assignment looks really unexpected to me.

@andrewbranch andrewbranch added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jan 6, 2020
@andrewbranch
Copy link
Member

If I use a regular import, I get This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValue' is set to 'error'.ts(1371)

This part sounds like a bug

@falsandtru
Copy link
Contributor

I believe the error Enum 'E' cannot be used as a value because only its type has been imported.ts(1362) is correct. You must not use a type as a value. And I believe base classes of ambient classes should be treated as having no value because ambient declarations just declare types of existing values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants