Skip to content

__extends fails to inherit static symbols #7529

Closed
@dpogue

Description

@dpogue

TypeScript Version:
1.8.7

Code

// A self-contained demonstration of the problem follows...
const test = Symbol('name');

class Foo {
    constructor() {
        console.log('Foo constructor');
    }
}

Foo[test] = 'testing a symbol';

class Bar extends Foo {
    constructor() {
        super();
        console.log('Bar constructor');
    }
}

let b = new Bar();
console.log(Bar[test]);

Expected behaviour:
Should output

Foo constructor
Bar constructor
testing a symbol

Actual behaviour:
Actual output is

Foo constructor
Bar constructor
undefined

This is because the __extends helper uses hasOwnProperty to check for properties to be copied over. Symbols are not properties, so they are never copied.

This works correctly with native ES6 classes, and with Babel's _inherits helper (using Object.setPrototypeOf rather than copying properties manually).

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions