Skip to content

Object.defineProperty(exports ...) is emitted even when exports is not defined #15685

Closed
@athasach

Description

@athasach

TypeScript Version: 2.3.2

Code

function fn(): void {}
export type MyType = number;

when compiled with a default tsconfig.json emits

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

Expected behavior:

It should not emit

Object.defineProperty(exports, "__esModule", { value: true });

if exports is not emitted in the compiled module.

Actual behavior:

Object.defineProperty(...) is emitted even if exports is not defined for the compiled module. When this code is loaded in a browser, it will throw an exception: Uncaught ReferenceError: exports is not defined.

If the MyType type declaration in the above code is not exported, then Object.defineProperty(...) is not emitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions