swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
30.92k stars 1.21k forks source link

Compile error on type and ts redefinitions #4148

Open tmayr opened 2 years ago

tmayr commented 2 years ago

Describe the bug

Cant import a type from another file with the same name as a definition in the current file unless you use it, getting is defined multiple times

When the type has the same name in the same file, it works fine When the type is being imported, and used, it works fine

I would expect same name values for types to work properly when imported or in the same file.

Input code

//a.ts
import { Foo } from "./b";
// import type { Foo } from "./b"; has the same behavior
const Foo = "hey";

// b.ts
export type Foo = string;

### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true
    },
    "target": "es2019"
  },
  "module": {
    "type": "commonjs"
  }
}

Playground link

No response

Expected behavior

Declarations and Types can have the same name when imported.

Actual behavior

  × the name `Foo` is defined multiple times
   ╭─[1:1]
 1 │ import { Foo } from "./b";
   ·          ─┬─
   ·           ╰── previous definition of `Foo` here
 2 │ const Foo = "hey";
   ·       ─┬─
   ·        ╰── `Foo` redefined here
   ╰────

Version

1.2.160

Additional context

No response

XantreDev commented 10 months ago
Error: 
@preact-signals/utils:build:   x the name `Uncached` is defined multiple times
@preact-signals/utils:build:     ,-[D:\Projects\open-source\preact-signals\packages\utils\src\$.ts:17:1]
@preact-signals/utils:build:  17 |  * <div>{$(() => sig.value * 10)}</div>
@preact-signals/utils:build:  18 |  * ```
@preact-signals/utils:build:  19 |  */
@preact-signals/utils:build:  20 | declare class Uncached<T> extends Signal<T> {
@preact-signals/utils:build:     :               ^^^^|^^^
@preact-signals/utils:build:     :                   `-- previous definition of `Uncached` here
@preact-signals/utils:build:  21 |   constructor(accessor: Accessor<T>);
@preact-signals/utils:build:  22 |   get value(): T;
@preact-signals/utils:build:  23 |   peek(): T;
@preact-signals/utils:build:  24 |   valueOf(): T;
@preact-signals/utils:build:  25 |   toString(): string;
@preact-signals/utils:build:  26 |   /** @internal */
@preact-signals/utils:build:  27 |   _a(): T;
@preact-signals/utils:build:  28 | }
@preact-signals/utils:build:  29 |
@preact-signals/utils:build:  30 | // @ts-expect-error
@preact-signals/utils:build:  31 | interface Uncached<T> extends JSX.Element {}
@preact-signals/utils:build:  32 |
@preact-signals/utils:build:  33 | function Uncached<T>(this: Uncached<T>, accessor: Accessor<T>) {
@preact-signals/utils:build:     :          ^^^^|^^^
@preact-signals/utils:build:     :              `-- `Uncached` redefined here
@preact-signals/utils:build:  34 |   this._a = accessor;
@preact-signals/utils:build:  35 | }
@preact-signals/utils:build:  36 | Uncached.prototype = Object.create(Signal.prototype);