Skip to content

TS does not recognize constructor assignments of unique symbol properties in JS #33129

Closed
@weswigham

Description

@weswigham

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

const _sym = Symbol("_sym");
class MyClass {
    constructor() {
        this[_sym] = "ok";
    }

    method() {
        this[_sym] = "yep";
        const x = this[_sym];
    }
}

included in a js file in a project with checkJs on.

Expected behavior:
MyClass has a member named [_sym]. Everything checks out.

Actual behavior:
Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'MyClass'.

Saw this while working on #32372 while looking at a suggestion on tapjs/tapjs#256. I think we'll want this fixed up for the next release, so it's ready alongside the js declaration emitter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallycheckJsRelates to checking JavaScript using TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions