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

Add type.d.ts declaration file for ESM usage #68559

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

jacobcassidy
Copy link
Contributor

@jacobcassidy jacobcassidy commented Jan 9, 2025

What?

Adds a declaration type.d.ts file to the @wordpress/prettier-config package so those using ESM imports don't get the warning: "Could not find a declaration file for module '@wordpress/prettier-config'".

Why?

Removes the annoying missing typescript declaration type warning by providing a declaration.

How?

Adds the following code (uses CommonJS by default, but allows ESM):

declare module '@wordpress/prettier-config' {
  const config: any;
  export = config;
}

Testing Instructions

  1. Install @wordpress/script
  2. Create an ESM prettier config file, such as prettier.config.mjs with the content import wpConfig from '@wordpress/prettier-config';
  3. See the underline under the @ in the VSCode editor that shows the warning.
  4. Add the index.d.ts file to the /node_modules/@wordpress/prettier-config/ of a working project.
  5. Note that the missing declaration warning is now gone.

Copy link

github-actions bot commented Jan 9, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jacobcassidy <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Tool] Prettier config /packages/prettier-config labels Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] Prettier config /packages/prettier-config [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants