microsoft / microsoft/TypeScript
__importStar sometimes inlined when using dynamic imports with --importHelpers
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with a.ts using tsc 3.1.1, --esModuleInterop, and --importHelpers, then inspect the emitted dynamic-import code. Trace how __importStar is selected for the Promise-based import and compare it with the working example that includes extends and export. Done means the failing case requires tslib and uses its __importStar helper instead of inlining it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100