Skip to content

Incorrect emitted declaration for unique symbol re-assignmentΒ #62305

@ernestostifano

Description

@ernestostifano

πŸ”Ž 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

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:

declare namespace myFunction {
    var mySymbol: unique symbol;
}

πŸ™‚ Expected behavior

Should be:

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions