Skip to content

unique symbol type lost after property is extracted from an objectΒ #43657

Closed

Description

Bug Report

Found while working on nodejs/node#38198

πŸ”Ž Search Terms

unique symbol object

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare const kSomeConstant: unique symbol;
declare function test(value: typeof kSomeConstant): void;
declare function getExports(): {
    kSomeConstant: typeof kSomeConstant;
    test: typeof test;
}

/*
    const exp: {
        kSomeConstant: typeof kSomeConstant;
        test: typeof test;
    }
*/
const exp = getExports()

// (property) kSomeConstant: typeof kSomeConstant
exp.test(exp.kSomeConstant)

// const constant: symbol
const constant = exp.kSomeConstant;
exp.test(constant);

πŸ™ Actual behavior

exp.test(constant) is an error, because constant's type is inferred to symbol instead of typeof kSomeConstant.

πŸ™‚ Expected behavior

The extracted variable should have the same type

Activity

  1. RyanCavanaugh commented on Apr 22, 2021

    @RyanCavanaugh
    Member

    This is the intended widening behavior of unique symbol, shown in a simpler example:

    declare const kSomeConstant: unique symbol;
    declare function test(value: typeof kSomeConstant): void;
    const p = kSomeConstant;
    test(p);

    A unique symbol type is never transferred from one declaration to another through inference.

  2. typescript-bot commented on Apr 24, 2021

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions