Skip to content

Typescript can't compile success while using some Symbol attributes #20572

Closed
@MSDimos

Description

@MSDimos

TypeScript Version: 2.6.2

Code

class Ite {

    [Symbol.toPrimitive](hint): number | string {
        switch (hint) {
            case 'number':
                return 100;
            case 'string':
                return "100";
            case "default":
                return "default";
            default:
                return null;
        }
    }
}
let ite: Ite = new Ite();

/*The following code hints the errors */
console.log(ite == 100);
console.log(ite + 100);
console.log(ite * 2);

Expected behavior:
JavaScript can run normally, and display the following content at the console

false
default100
200

but typescript can't compile success. And many of the rest of the Symbol attributes are not normally identified. Such as Symbol.species.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions