microsoft / microsoft/TypeScript

Incorrect emitted declaration for unique symbol re-assignment

Open
#62,305 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Declaration Emit Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 Search Terms

"TS1332", "unique symbol readonly", "function readonly property"

### 🕗 Version & Regression Information

N/A.

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250819#code/MYewdgzgLgBAtgTwMoLgIxAGxgXhi9LACgHICNMIA6RcrEgSgG4AoF0SWOy3GAbxYwh8ZKgosAvjACGEGB2isWAMwCuYYFACW4EQDF1mnWCIN+EtogMbt4GqMLY83arTFYlAegBULJAFF-GAADKgARKgAVJGCYSIBBACEqOIAJIKSAeQA1IIBhTLCggAUAJUKAVTz-JAAuNgATAFNgTGkAJyaYMGk4JogAB2lgLqtDWzB+QWEANw6RblqYdS0AR1UuiHdMVgsWAHVUgEk81JgjpBh4gDkYf1Ly0pgiaIBGAGZ3gCYl+Jg59paaRoTBdADuAAsQBAulAEAMulo5NIYCQVutNtsSDA4Qj4KpoDA0F0FFAGCxvJ42E0AB4DEDtWB8MY2YwWIA

### 💻 Code

```ts
const mySymbol = Symbol('Symbols.mySymbol');

const Symbols = {
mySymbol
} as const;

function myFunction() {}

myFunction.mySymbol = Symbols.mySymbol;

/*
SEE `.D.TS` TAB. THE ABOVE CODE PRODUCES:

declare namespace myFunction {
var mySymbol: unique symbol;
}

WHICH IS AN ERROR (TS1332: A variable whose type is a 'unique symbol' type must be const)
*/

export {myFunction}
```

### 🙁 Actual behavior

Compiler produces:

```ts
declare namespace myFunction {
var mySymbol: unique symbol;
}
```

### 🙂 Expected behavior

Should be:

```ts
declare namespace myFunction {
const mySymbol: unique symbol;
}
```

### Additional information about the issue

Behaves differently when not in a module (remove `export {myFunction}` in the Playground)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground reproduction and inspect declaration emission for the assigned property on an exported function, comparing module and non-module behavior. The fix is done when the emitted declaration uses `const mySymbol: unique symbol` rather than `var`, while preserving the reported output in the other case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.