question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typescript transform confused about types and values with the same name

See original GitHub issue

Bug 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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dollysingh3192commented, Oct 13, 2020

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?

2reactions
loganfsmythcommented, May 16, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found