X Tutup
The Wayback Machine - https://web.archive.org/web/20210126131419/https://github.com/microsoft/TypeScript/issues/38009
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique symbol can't be used to index class #38009

Open
ilogico opened this issue Apr 16, 2020 · 1 comment
Open

Unique symbol can't be used to index class #38009

ilogico opened this issue Apr 16, 2020 · 1 comment
Assignees
Labels

Comments

@ilogico
Copy link

@ilogico ilogico commented Apr 16, 2020

TypeScript Version: 3.8.3 and next (3.7.x works as expected)

Search Terms: unique symbol class expression

Code

// tsc --target esnext --strict
const s = Symbol();

class A {
    [s]: number;
    constructor() {
        this[s] = 42;
    }
}

const B = class {
    [s]: number;
    constructor() {
        this[s] = 42;
    }
}

const C = true && class {
    [s]: number;
    constructor() {
        this[s] = 42;
    }
}

Expected behavior:
No errors
Actual behavior:
error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'B'.
Property '[s]' does not exist on type 'B'.

13 this[s] = 42;
Playground Link

Related Issues: Did not find any

Only the B example doesn't work. It doesn't matter if the class is named or not. Returning the class from a IIFE also works without errors.

@kiroushi
Copy link

@kiroushi kiroushi commented May 6, 2020

Managed to reproduce this issue while implementing a singleton pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
X Tutup