Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__importDefault method may return an object with undefined default property #190

Open
NealST opened this issue Dec 21, 2022 · 2 comments
Open

Comments

@NealST
Copy link

NealST commented Dec 21, 2022

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.

@rbuckton
Copy link
Member

rbuckton commented May 2, 2023

Looking at typedoc, it does have an __esModule property, so perhaps you are importing it incorrectly? Which import style are you using:

// (1)
import typedoc from "typedoc";

// (2)
import * as typedoc from "typedoc";

Typedoc does not specify a default export, so you may need to use (2).

@NealST
Copy link
Author

NealST commented May 4, 2023

yeah, you are right, but this design will result to the increasing cost of using tslib, developer must know whether the library has a default export firstly, and then they decide to how to import the library. I think this is not a good experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants