Typescript: Module with "Object" export has bad ES5 emit

Created on 28 Jul 2017  ·  3Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 2.2 to current

Code
TS file:
export class Object {}
tsconfig.json:
{"compilerOptions": {"target": "es5"}}

Expected behavior:
The module should be able to initialize like it did in TypeScript 2.1.

Actual behavior:
Module fails to initialize; TypeError: Object is undefined.

The emitted code is

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Object = (function () {
    function Object() {
    }
    return Object;
}());
exports.Object = Object;

Clearly Object.defineProperty is intended to reference the global Object, but it gets an uninitialized local variable instead.

Bug Fixed help wanted

All 3 comments

As a temporary workaround, you can name your class _Object and write export { _Object as Object }

This should be an error, similar to the error we issue if you declare your own _this.

PRs welcomed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanzer picture seanzer  ·  3Comments

kyasbal-1994 picture kyasbal-1994  ·  3Comments

CyrusNajmabadi picture CyrusNajmabadi  ·  3Comments

MartynasZilinskas picture MartynasZilinskas  ·  3Comments

bgrieder picture bgrieder  ·  3Comments