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

fix TypeScript declarations #121

Closed
wants to merge 1 commit into from
Closed

fix TypeScript declarations #121

wants to merge 1 commit into from

Conversation

eventualbuddha
Copy link
Contributor

There's no default export, so don't use default exports in the type declarations. Also fixes a few other issues.

There's no default export, so don't use default exports in the type declarations. Also fixes a few other issues.
@Rich-Harris
Copy link
Owner

Thanks — not sure I understand what you mean by there being no default export? pkg.main has a module.exports =, but pkg.module has both a default and a named export (index.js corresponds to pkg.module, index-legacy.js to pkg.main).

@eventualbuddha
Copy link
Contributor Author

@eventualbuddha
Copy link
Contributor Author

An alternative way to fix this is to add a default property to MagicString which also refers to MagicString.

@Rich-Harris
Copy link
Owner

Gah. Looks like the problem here is that ts-node is importing pkg.main rather than pkg.module. Does that sound right? If so, adding MagicString.default = MagicString here probably is the best fix, yes.

@eventualbuddha
Copy link
Contributor Author

It's not specific to ts-node. This is what TypeScript generates:

"use strict";
exports.__esModule = true;
var magic_string_1 = require("magic-string");
new magic_string_1["default"]('abc');

So yeah, maybe do this?

Object.defineProperty(MagicString, 'default', { value: MagicString });

@Rich-Harris
Copy link
Owner

Will do — though I consider the lack of interoperability a bug in TypeScript!

@eventualbuddha
Copy link
Contributor Author

Will do — though I consider the lack of interoperability a bug in TypeScript!

Here's a long discussion about it: microsoft/TypeScript#2719.

@Rich-Harris
Copy link
Owner

Lordy. Imagine if the JS gods had given us modules that didn't have privileged default exports, or if Node hadn't decided to tear up CommonJS 1.1 in the first place. We could probably have transitioned the whole ecosystem by now...

@Rich-Harris
Copy link
Owner

Have released 0.21.2 with that change, so I'll close this. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants