microsoft / microsoft/tslib

__importDefault method may return an object with undefined default property

Open
#190 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

In my project, I use tslib as the helper library.
Today, I come across a mistake like this:
image

the error line code that generated by tsc is:

typedocApp = new typedoc_1.default.Application();

and typedoc_1 is defined like this:

var typedoc_1 = tslib_1.__importDefault(require("typedoc"));

So, I readed the code of __importDefault method in tslib:

 __importDefault = function (mod) {
        return (mod && mod.__esModule) ? mod : { "default": mod };
    };

If a mod has __esModule property but does not have default property, such as typedoc, the error described above will be fired.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the __importDefault helper implementation and reproduce the reported case with a module that has __esModule but no default property. Trace the generated import usage shown in the issue and add or update coverage for that case; done means the helper no longer produces the reported undefined default behavior without breaking ordinary CommonJS interop.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.