Skip to content

Can't evaluate equality of symbols made by Symbol.for #35909

Open
@falsandtru

Description

@falsandtru

This is also an obstacle of branded types and ghost types. I think resolving this problem is easy because these types are just a new literal type similar to string literal types.

TypeScript Version: 3.7.x-dev.20191228

Search Terms:

Code

const a = Symbol.for('');
const b = Symbol.for('');
const c: typeof b = Symbol.for(''); // error
a === b; // error

Expected behavior:
no error
Actual behavior:
Type 'typeof b' is not assignable to type 'typeof a'.
This condition will always return 'false' since the types 'typeof a' and 'typeof b' have no overlap.
Playground Link: https://www.typescriptlang.org/play/index.html?ts=3.8.0-dev.20191228&ssl=1&ssc=1&pln=4&pc=18#code/MYewdgzgLgBAhjAvDAygTwLYCMQBsB0AZiAE4AUA5BQJQDcAUKJLFkqpjgceVXY+NBjAAXDChoADgFMQhGK2TpseIqUo1aMAPRaYUkiVL0EiU-M069B0kA

Related Issues: #35200

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions