microsoft / microsoft/TypeScript

`export { _void as void }` leads to exporting duplicate identifiers

Open
#62,081 1 comment 0 reactions 0 assignees View on GitHub
Bug Domain: Declaration Emit Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 Search Terms

`export void` `export reserved` `export null`

### 🕗 Version & Regression Information

- Reproducible since typescript v4. In older releases, it doesn't export anything. I also tried the latest dev release (5.9.0-dev.20250716)
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about `exports`

### ⏯ Playground Link

[Playground (important: lang:javascript)](https://www.typescriptlang.org/play/?target=99&jsx=0&filetype=js#code/FAUwHgDg9gTgLgAgMZQHYGdEH0BuUCWAJggLwIDeAvsKJLIuQrgcQIboJ5EKUI1A)

### 💻 Code
Using the following `tsconfig.json`:

```json
{
"compilerOptions": {
"target": "esnext",
"lib": ["esnext"],
"module": "esnext",
"allowJs": true,
"checkJs": true,
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"emitDeclarationOnly": true,
"strict": true,
"noImplicitAny": true,
"moduleResolution": "bundler"
}
}
```

I compile declaration files for this code `${project}/schema.js` (only happens when compiling javascript):

```ts
const _null = {}
const $void = {}

export { _null as null, $void as void }
```

### 🙁 Actual behavior

The produced declaration file `schema.d.ts` is erroneous. It has duplicate identifiers:

```ts
declare const _null: {};
declare const $void: {};
export { _null as null, _null as null, $void as void, _void as void };
```

### 🙂 Expected behavior

No duplicate identifiers:

```ts
declare const _null: {};
declare const $void: {};
export { _null as null, $void as void };
```

### Additional information about the issue

For any reserved keyword, `tsc` always exports `_{reserved} as {reserved}`, whenever `{reserved}` is exported. Even though the variable `_{reserved}` does not exist.

It is only reproducible when compiling javascript.

Contributor guide

Open the contributing guide

Research direction

Start with the provided tsconfig.json and schema.js reproduction, then inspect JavaScript declaration-only emit for the export list. Compare the generated schema.d.ts with the expected export statements; done means reserved-keyword exports appear once and no nonexistent identifiers are emitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.