typescript transform confused about types and values with the same name
See original GitHub issueBug Report
Current Behavior
babel is confused about a duplicate declaration when a type is imported and a value with the same name is declared locally. See code below.
Input Code
The following code results in a “Duplicate declaration” error, but is accepted by TypeScript (the compiler). It’s because the SomeThing
import is a type (for example export interface SomeThing{}
), whereas the local const declaration is a value, so the two are not actually in any conflict.
import { SomeThing } from './module';
const SomeThing = 1;
Expected behavior/code
The babel typescript transform should accept the same code as the typescript compiler.
Babel Configuration (.babelrc, package.json, cli command)
module.exports = {
presets: [
"next/babel",
"@zeit/next-typescript/babel"
],
plugins: [
["react-intl", { messagesDir: "./locale/en/messages/" }],
["emotion", { inline: true, autoLabel: true }],
["transform-define", require("./env.js")]
]
};
Environment
- Babel version(s): @babel/plugin-syntax-typescript@7.0.0-beta.47
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Typescript: Intersection - Confused about the naming
An intersection between two sets would yield elements that are in both sets. Types are just descriptions of sets of values.
Read more >No More Confusion About TypeScript's Type and Interface
Interfaces with the same name are automatically merged(Declaration Merging), while type aliases are not: Using the feature of declaration merging ...
Read more >5 Utility Types For Transforming Types in Typescript
You can transform, change, and create new types using existing types. In this article, we will look at 5 such utility types that...
Read more >Documentation - Namespaces - TypeScript
Another way that you can simplify working with namespaces is to use import q = x.y.z to create shorter names for commonly-used objects....
Read more >TypeScript Maybe Type and Module - DSC Engineering
Now, within case MaybeType.Nothing: , TypeScript knows that maybeName doesn't have a .value property. Similarly, within case MaybeType.Just: ...
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
Facing similar issue and posted on Stack Overflow as well with minimal reproduction on Github repo:
https://stackoverflow.com/questions/64323473/typeerror-duplicate-declaration-module-build-failed-error-in-typescript-projec
Any plans on this issue to be fix in near future?
@andy-ms Any thoughts on this? To me it seems like a place where we’d accept that Babel behaves differently from TS because TS overrode the standard spec behavior.