-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: generate index.d.mts and index.d.cts #273
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xiaoxiangmoe
force-pushed
the
main
branch
2 times, most recently
from
June 25, 2023 07:25
883e68d
to
ebbbeab
Compare
lsdsjy
reviewed
Jun 26, 2023
xiaoxiangmoe
commented
Jun 26, 2023
lsdsjy
approved these changes
Jun 30, 2023
/cc @danielroe |
antfu
reviewed
Jul 4, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good to me. But should we generate a fallback of .d.ts
for the libraries that still rely on it to avoid breakage?
xiaoxiangmoe
commented
Jul 4, 2023
xiaoxiangmoe
force-pushed
the
main
branch
2 times, most recently
from
July 4, 2023 10:42
bb4e837
to
bafc9d0
Compare
pi0
reviewed
Jul 4, 2023
friendly ping @pi0 @danielroe |
danielroe
approved these changes
Jul 18, 2023
This was referenced Jul 18, 2023
Closed
9 tasks
sentience
added a commit
to cultureamp/js-lingui
that referenced
this pull request
Aug 24, 2023
The recent lingui#1742 explicitly exports TypeScript type definitions from package.json: ```json "exports": { ".": { "require": { "types": "./dist/index.d.ts", "default": "./dist/index.cjs" }, "import": { "types": "./dist/index.d.ts", "default": "./dist/index.mjs" } }, "./package.json": "./package.json" }, ``` Unfortunately, [as documented in the TypeScript Handbook][handbook], CommonJS (`require`) and ESM (`import`) module versions cannot share the same index.d.ts file: > It’s important to note that the CommonJS entrypoint and the ES module entrypoint each needs its own declaration file, even if the contents are the same between them. Every declaration file is interpreted either as a CommonJS module or as an ES module, based on its file extension and the "type" field of the package.json, and this detected module kind must match the module kind that Node will detect for the corresponding JavaScript file for type checking to be correct. Attempting to use a single .d.ts file to type both an ES module entrypoint and a CommonJS entrypoint will cause TypeScript to think only one of those entrypoints exists, causing compiler errors for users of the package. I am seeing the compiler errors that this documentation warns of. This issue appears to have been recently fixed in the unbuild build tool that js-lingui depends upon (see issue unjs/unbuild#238 and fix unjs/unbuild#273), and that fix was released in [unbuild 2.0.0-rc0]. This fix for detect-locale, therefore, is to upgrade to unbuild 2.0.0, and use the separate .d.cts and .d.mts type declaration files it outputs. **Note:** This moves detect-locale onto a newer major version of unbuild than the other packages in this monorepo. It may be preferred to upgrade them all, but I am not familiar enough with the other packages to do this quickly. [handbook]: https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing [unbuild 2.0.0-rc0]: https://github.com/unjs/unbuild/blob/main/CHANGELOG.md#v200-rc0
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
close #238