Skip to content

__importStar sometimes inlined when using dynamic imports with --importHelpers #27415

Open
@dgoldstein0

Description

@dgoldstein0

TypeScript Version: 3.1.1

Search Terms: __importStar tslib

Code
a.ts:

import('b').then(b => console.log(b));

compile with

tsc a.ts --esModuleInterop --importHelpers

Expected behavior:
some type errors, but emitted code should require("tslib") and use __importStar from there

Actual behavior:
some type errors and generated code looks like this:

var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Promise.resolve().then(function () { return __importStar(require('b')); }).then(function (b) { return console.log(b); });

btw an example that works correctly:

import('c').then(b => console.log(b));

class Foo {}

export class Bar extends Foo {}

both the extends and the export seem to be necessary

Playground Link: N/A (--esModuleInterop doesn't exist in the playground)

Related Issues: This is basically #21560 but replacing regular imports with dynamic imports

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions