Skip to content

Directory Compilation based on tsconfig.json to Properly Order Inherited Classes #3098

@bmingles

Description

@bmingles

When a tsconfig.json file is used to target a directory instead of an explicit file list, inherited classes aren't guaranteed to be ordered correctly unless they contain /// <reference tags. It would be nice if directory based compilation could work out the order for inherited classes without the need for the extra tags.

eg.
If i have an empty tsconfig.json file:

{}

A base class:

/** Base class */
class ServiceBase {
}

And inheriting class:

/** Child class */
class MyService extends ServiceBase {
    constructor(){
        super();
    }
}

And a project structure like:

ProjectDir
--MyService.ts
--ServiceBase.ts
--tsconfig.json

The output .js will output the child class before the base class which gives runtime errors:

var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
/** Child class */
var MyService = (function (_super) {
    __extends(MyService, _super);
    function MyService() {
        _super.call(this);
    }
    return MyService;
})(ServiceBase);
/** Base class */
var ServiceBase = (function () {
    function ServiceBase() {
    }
    return ServiceBase;
})();

If I add a reference comment to my child class, the ordering will be correct:

/// <reference path="ServiceBase.ts"/>

I'd like to not have to do this, since the reference tags no longer seem necessary for most other use cases:

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions