Skip to content

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

Open
jacobcassidy wants to merge 2 commits intoWordPress:trunkfrom
jacobcassidy:wp-prettier-config-type
Open

Add type.d.ts declaration file for ESM usage#68559
jacobcassidy wants to merge 2 commits intoWordPress:trunkfrom
jacobcassidy:wp-prettier-config-type

Conversation

@jacobcassidy
Copy link
Copy Markdown
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.

@github-actions
Copy link
Copy Markdown

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 <jacobcassidy@git.wordpress.org>

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