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: exports types #183

Closed
wants to merge 3 commits into from
Closed

fix: exports types #183

wants to merge 3 commits into from

Conversation

stefan-karlsson
Copy link

@stefan-karlsson stefan-karlsson commented Jul 30, 2023

Makes sure that the correct Typescript definitions are exported when export property in package.json is used.

Issue reference: #170

Makes sure that the correct Typescript definitions is exported when exports property in package.json is used.
@MilanKovacic MilanKovacic self-requested a review October 2, 2023 08:34
Copy link
Contributor

@MilanKovacic MilanKovacic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for submitting the PR. There are still some problems left to fix. Let me know if you need any help. See the following image:

image

Testing done with https://arethetypeswrong.github.io/.
Essentially, exports need to be reformatted (split) as follows:

{
  "exports": {
    ".": {
      "import": {
        "types": "./index.d.ts",
        "default": "./index.js"
      },
      "require": {
        "types": "./index.d.cts",
        "default": "./index.cjs"
      }
    }
  }
}

There also has to be an additional types declaration file (see index.d.cts in the example) for the CJS format.
After reviewing the code, there is a mix of default and named exports which can (rarely) cause problems when package is consumed in CJS format (see https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/CJSOnlyExportsDefault.md). Rollup does not correctly handle this case, so the solution is to either patch the code to add the interopability, patch the output, or remove the default export (which is of course, a breaking change). This one can wait 😄

@NathanKleekamp
Copy link

@stefan-karlsson @MilanKovacic Thank you both for your efforts at continuing to improve this lib. Any chance we can get this PR updated and merged?

@MilanKovacic
Copy link
Contributor

@stefan-karlsson If you do not have time to make the proposed changes, let me know and I will do them.

@stefan-karlsson
Copy link
Author

@stefan-karlsson If you do not have time to make the proposed changes, let me know and I will do them.

You are free to help out if you want. Have quite a lot at my work atm :)

@thejayhaykid thejayhaykid mentioned this pull request Oct 13, 2023
@stefan-karlsson
Copy link
Author

Close in favor of #196

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.

3 participants