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

__extends fails to inherit static symbols #7529

Closed
dpogue opened this issue Mar 15, 2016 · 0 comments
Closed

__extends fails to inherit static symbols #7529

dpogue opened this issue Mar 15, 2016 · 0 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@dpogue
Copy link

dpogue commented Mar 15, 2016

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).

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Mar 15, 2016
@dpogue dpogue closed this as completed Oct 18, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants