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

Incomplete Metadata for subclass with default constructor #13410

Closed
ajafff opened this issue Jan 11, 2017 · 2 comments
Closed

Incomplete Metadata for subclass with default constructor #13410

ajafff opened this issue Jan 11, 2017 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ajafff
Copy link
Contributor

ajafff commented Jan 11, 2017

TypeScript Version: 2.1.4

tsc is run with --experimentalDecorators and --emitDecoratorMetadata

Code

function foo(_: any) {}

@foo
class Foo {
    constructor(public bar: number) {}
}
@foo
class Bar extends Foo {
}

Expected behavior:

 Bar = __decorate([
     foo,
-    __metadata("design:paramtypes", [])
+    __metadata("design:paramtypes", [Number])
 ], Bar);

Metadata for subclass with default constructor should include parameter types of super constructor.

Actual behavior:

tsc emit:

/* ... helper functions ... */

function foo(_) { }
var Foo = (function () {
    function Foo(bar) {
        this.bar = bar;
    }
    return Foo;
}());
Foo = __decorate([
    foo,
    __metadata("design:paramtypes", [Number])
], Foo);
var Bar = (function (_super) {
    __extends(Bar, _super);
    function Bar() {
        return _super.apply(this, arguments) || this;
    }
    return Bar;
}(Foo));
Bar = __decorate([
    foo,
    __metadata("design:paramtypes", [])
], Bar);
@mhegazy
Copy link
Contributor

mhegazy commented Jan 11, 2017

This is behaving as intended. the derived class does not have a constructor, the compiler can not just delegate the constructor in the general case. Consider a case where the type of the argument in the base class is not accessible to the derived. the emit would be invalid. Noting that the output generation needs to work as single file transformation (i.e. in isolation of the rest of the project) . e.g.:

// File1.ts
class Inner { }
export class Base {
    constructor (p: Inner) {}
}
//File2.ts
import {Base} from "./File1";
class Derived extends Base {} // Inner here is not visible

If you are using TS 2.2 (specifically the change to __extends in #12488) you should be able to get the parent meta data by walking up the prototype chain.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 11, 2017
@ajafff
Copy link
Contributor Author

ajafff commented Jan 11, 2017

That sounds pretty reasonable.
Feel free to close this issue.

@mhegazy mhegazy closed this as completed Jan 11, 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
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants