TypeScript: enum member with the same name as an imported type prevents import stripping
See original GitHub issueBug Report
Current Behavior
If the name of an enum
member matches that of an imported type, the corresponding import
statement remains through transpilation, even if it’s never referenced.
Input Code
import Foo from 'some-module';
enum Enum {
Foo
}
function myFunction(): Foo {}
Expected behavior/code
I expect not to see import Foo from 'some-module';
in the compiled output, since Foo
is only ever used as a type.
Note that changing the name of the enum
member, e.g. to Foo2
, causes the import
statement to be stripped.
Environment
@babel/core
: 7.1.2@babel/plugin-transform-typescript
: 7.1.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
typescript - How to import an Enum - Stack Overflow
I'm using global TS importing and TS can't see the exported enum that I have put in a different file for this very...
Read more >Handbook - Enums - TypeScript
String enums allow you to give a meaningful and readable value when your code runs, independent of the name of the enum member...
Read more >TypeScript: Don't Export const enums - ncjamieson
the compiler reads a TypeScript module;; the module's type information is stripped; and; what's left is the JavaScript module that the compiler ...
Read more >TypeScript Fundamentals - Joy of Code
Your editor already has some great features that get enhanced by TypeScript: Auto imports (as you type imports get added); Code navigation (definitions, ......
Read more >48 answers on StackOverflow to the most popular Angular ...
Importing lodash into angular2 + typescript application ... Only the value false or removing the attribute will actually make the element ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@dfreeman I assume changing the name of the import also fixes the problem, i.e. with this?
This is a real bug. In this example the no-unused-variable rule wouldn’t warn: