Skip to content

Explicitly annotated unique symbols are widened in return positionsΒ #55361

Open
@Andarist

Description

@Andarist

πŸ”Ž Search Terms

widening return unique symbol

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.0-dev.20230814&ssl=6&ssc=2&pln=1&pc=1#code/KYDwDg9gTgLgBAYwgOwM7xsdcC8cDKAngLYBGEANgBQCUAUHaJLHAGYCuyCMAlim8lpwA3nTjjEKbAEMKPaagBccGITDAIrFVnh5M6ANxiJUYDHZRkcWfNR0AvkA

πŸ’» Code

export const test = Symbol()

export function fn() {
    const alias: typeof test = test;
    return alias
}

πŸ™ Actual behavior

this declaration file is emitted:

export declare const test: unique symbol;
export declare function fn(): symbol;

πŸ™‚ Expected behavior

this declaration file to be emitted:

export declare const test: unique symbol;
export declare function fn(): typeof test;

Additional information

getWidenedLiteralLikeTypeForContextualReturnTypeIfNeeded calls getWidenedLiteralLikeTypeForContextualType and that calls getWidenedUniqueESSymbolType when there is no contextual type provided.

some issues that are (partially~) related:
#32242
#35896 (comment)
#36876

Metadata

Metadata

Assignees

No one assigned

    Labels

    Possible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions