Skip to content

Import simplification too aggressive for transpileOnly in super call #24620

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

Closed
MehdyKarimpour opened this issue Jun 2, 2018 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@MehdyKarimpour
Copy link

MehdyKarimpour commented Jun 2, 2018

TypeScript Version: 2.9.1

Search Terms: transpile-only import

Code

import { QueryEntity } from '../../../Framework/Signum.React/Scripts/Signum.Entities.Basics'
import { ToolbarConfig, ToolbarResponse } from './ToolbarClient'

export default class QueryToolbarConfig extends ToolbarConfig<QueryEntity> {
    constructor() {
        super(QueryEntity);
    }
}

Expected behavior:
QueryEntity is imported in the generated JS.

Actual behavior:
QueryEntity is simplified away.

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _Framework_Signum_React_Scripts_Reflection__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../Framework/Signum.React/Scripts/Reflection */ "../Framework/Signum.React/Scripts/Reflection.ts");
/* harmony import */ var _Framework_Signum_React_Scripts_Finder__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../Framework/Signum.React/Scripts/Finder */ "../Framework/Signum.React/Scripts/Finder.tsx");
/* harmony import */ var _ToolbarClient__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ToolbarClient */ "../Extensions/Signum.React.Extensions/Toolbar/ToolbarClient.tsx");
var __extends = (undefined && undefined.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var QueryToolbarConfig = /** @class */ (function (_super) {
    __extends(QueryToolbarConfig, _super);
    function QueryToolbarConfig() {
        return _super.call(this, QueryEntity) || this; //<--- problem here 
    }
}
bundle.main.1e1e130d262a7c0b7498.js:6772 Uncaught (in promise) ReferenceError: QueryEntity is not defined
    at new QueryToolbarConfig (bundle.main.1e1e130d262a7c0b7498.js:6772)
    at bundle.main.1e1e130d262a7c0b7498.js:30387

The problem is fixed just by assigning QueryEntity to a variable first:

export default class QueryToolbarConfig extends ToolbarConfig<QueryEntity> {
    constructor() {
        var a = QueryEntity; 
        super(a);
    }
}
MehdyKarimpour added a commit to MehdyKarimpour/extensions that referenced this issue Jun 2, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 2, 2018

Duplicate of #24551, fixed by #24591.

Fix should be already in typescript@next today, and in typescript@2.9.2 in two weeks.

@phiresky
Copy link

phiresky commented Jun 5, 2018

This is pretty annoying since it blocks use of TS 2.9 when running with a large project with type errors / partially typed files (forcing use of transpileOnly). Any way to get this fix to a stable version faster?

This is the issue causing TypeStrong/ts-node#591

Also the proposed workaround is impossible in all of my instances because of [ts] A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties.

Edit: Had 4 instances of this issue in my project. Now I have four useless statements in my code.

@phiresky
Copy link

phiresky commented Jun 5, 2018

This also happens when using webpack. Even worse: This error is only noticed once an instance of the corresponding class is constructed at runtime, which might only happen seldom and thus not be noticed.

I have many files that look like this:

import config from "client/config";

class Something extends XYZ {
	constructor() {
		super(config.var); [...]
	}

I can't even find all instances of this error without it crashing my code randomly and fixing it when it does.

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants