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

Emit of union type metadata of two classes inherited from the same parent are Object and not common ancestor #12705

Closed
dqweek opened this issue Dec 7, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@dqweek
Copy link

dqweek commented Dec 7, 2016

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)

Code

function dec(): PropertyDecorator {
    return (target: any, key: string | symbol): void => { };
}

class UseCase { }

class Child1 extends UseCase {
}
class Child2 extends UseCase {
}

class D {
    @dec()
    field: Child1 | Child2;
}

Expected behavior:

function dec() {
    return function (target, key) { };
}
var UseCase = (function () {
    function UseCase() {
    }
    return UseCase;
}());
var Child1 = (function (_super) {
    __extends(Child1, _super);
    function Child1() {
        _super.apply(this, arguments);
    }
    return Child1;
}(UseCase));
var Child2 = (function (_super) {
    __extends(Child2, _super);
    function Child2() {
        _super.apply(this, arguments);
    }
    return Child2;
}(UseCase));
var D = (function () {
    function D() {
    }
    __decorate([
        dec(), 
        __metadata('design:type', UseCase)
    ], D.prototype, "field", void 0);
    return D;
}());

Actual behavior:

function dec() {
    return function (target, key) { };
}
var UseCase = (function () {
    function UseCase() {
    }
    return UseCase;
}());
var Child1 = (function (_super) {
    __extends(Child1, _super);
    function Child1() {
        _super.apply(this, arguments);
    }
    return Child1;
}(UseCase));
var Child2 = (function (_super) {
    __extends(Child2, _super);
    function Child2() {
        _super.apply(this, arguments);
    }
    return Child2;
}(UseCase));
var D = (function () {
    function D() {
    }
    __decorate([
        dec(), 
        __metadata('design:type', Object) // <-- expected to be UseCase
    ], D.prototype, "field", void 0);
    return D;
}());

Related Issues
#12703

@dqweek dqweek changed the title Emit of union type metadata is of two classes inherited from the same parent are Object Emit of union type metadata of two classes inherited from the same parent are Object and not common ancestor Dec 7, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

This is a duplicate of #12703. all union types are treated the same way.

@mhegazy mhegazy closed this as completed Dec 7, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 7, 2016
@dqweek
Copy link
Author

dqweek commented Dec 7, 2016

Why they need to be treated the same, is it difficult to reflect the common ancestor of Union of types ?
Of course all types have common ancestor (object type) by default, but still it would be nice to emit something more descriptive, so we could use it in runtime

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants