Skip to content

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

Closed
@targos

Description

@targos

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

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