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

Export types #51

Merged
merged 1 commit into from
Jul 5, 2023
Merged

Export types #51

merged 1 commit into from
Jul 5, 2023

Conversation

privatenumber
Copy link
Sponsor Contributor

No description provided.

@sindresorhus
Copy link
Owner

This is a breaking change for TS users, so I prefer to do it myself in the next major release. The types are already implicitly exported as it's named index.d.ts, which TS should check.

@privatenumber
Copy link
Sponsor Contributor Author

How is it a breaking change?

@sindresorhus
Copy link
Owner

sindresorhus/got#2267

@privatenumber
Copy link
Sponsor Contributor Author

That's a breaking changes because the types property was removed from package.json. In this case, it's not because index.d.ts is at the root of the package where it can be detected.

In Node10 resolution mode, tsc checks the types property, and then falls back to checking index.d.ts at the root of the package. Therefore, that issue can be fixed by adding the top-level types property back. Node10 will look at types & Node16 will look at exports.types.

Here's the resolution trace using moduleResolution: "node" (via tsc --traceResolution):

======== Resolving module 'copy-text-to-clipboard' from '/index.ts'. ========
Explicitly specified module resolution kind: 'Node10'.
Loading module 'copy-text-to-clipboard' from 'node_modules' folder, target file types: TypeScript, Declaration.
Found 'package.json' at '/node_modules/copy-text-to-clipboard/package.json'.
File '/node_modules/copy-text-to-clipboard.ts' does not exist.
File '/node_modules/copy-text-to-clipboard.tsx' does not exist.
File '/node_modules/copy-text-to-clipboard.d.ts' does not exist.
'package.json' does not have a 'typesVersions' field.
'package.json' does not have a 'typings' field.
'package.json' does not have a 'types' field.
'package.json' does not have a 'main' field.
File '/node_modules/copy-text-to-clipboard/index.ts' does not exist.
File '/node_modules/copy-text-to-clipboard/index.tsx' does not exist.
File '/node_modules/copy-text-to-clipboard/index.d.ts' exists - use it as a name resolution result.
Resolving real path for '/node_modules/copy-text-to-clipboard/index.d.ts', result '/node_modules/copy-text-to-clipboard/index.d.ts'.
======== Module name 'copy-text-to-clipboard' was successfully resolved to '/node_modules/copy-text-to-clipboard/index.d.ts' with Package ID 'copy-text-to-clipboard/[email protected]'. ========

Reproduction: https://stackblitz.com/edit/stackblitz-starters-hhbdf4?file=index.ts

@sindresorhus sindresorhus reopened this Jul 5, 2023
@sindresorhus sindresorhus merged commit dfd2874 into sindresorhus:main Jul 5, 2023
4 checks passed
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