Closed
Labels
Description
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 Andrew Branch (@andrewbranch) in #35200
Activity
ajafff commentedon Jan 4, 2020
Also note that the type-only import of the const enum is reported as unused.
andrewbranch commentedon Jan 6, 2020
I see the motivation, but
import typemeans 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: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 commentedon Jan 6, 2020
This part sounds like a bug
falsandtru commentedon Jan 6, 2020
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.