Skip to content

fix(react): declare @types/react as an optional peer dependency - #1418

Open
abdul-karim-mia wants to merge 1 commit into
tailwindlabs:masterfrom
abdul-karim-mia:fix/react-types-peer-dependency
Open

abdul-karim-mia wants to merge 1 commit into
tailwindlabs:masterfrom
abdul-karim-mia:fix/react-types-peer-dependency

Conversation

@abdul-karim-mia

Copy link
Copy Markdown

Closes #1417.

Summary

@heroicons/react ships type declaration files (.d.ts) that import from react (import * as React from 'react').

Under strict or isolated installation layouts (such as pnpm with virtualStoreType: global, Yarn PnP, or Bun's isolated linker), packages resolve dependencies and peer dependencies from their real disk locations. Because @types/react was not declared as a peer dependency, TypeScript resolves react to the untyped react/index.js file rather than @types/react/index.d.ts. As a result, React types in @heroicons/react components can degrade to any or trigger compiler errors (e.g. TS7006: Parameter 'x' implicitly has an 'any' type).

Solution

Declare @types/react as an optional peer dependency in react/package.json:

  "peerDependencies": {
    "@types/react": "*",
    "react": ">= 16 || ^19.0.0-rc"
  },
  "peerDependenciesMeta": {
    "@types/react": {
      "optional": true
    }
  }
  • Marked as "optional": true under peerDependenciesMeta so plain JavaScript consumers never receive peer dependency warnings.
  • Uses * to accommodate any supported React version (16, 17, 18, 19) without restrictive version bounds.
  • Follows established conventions across the React ecosystem (e.g. @tanstack/react-query, @radix-ui/*, recharts #7710, react-router).

Verification

  • Ran npm run lint (node ./scripts/verify-names.js): passed (All good!).
  • Ran node ./scripts/build.js react: rebuilt cleanly with 0 errors and preserved exports.
  • Ran npx prettier --check react/package.json: formatted cleanly.

Closes tailwindlabs#1417

Signed-off-by: Abdul karim mia <97598943+abdul-karim-mia@users.noreply.github.com>
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.

@heroicons/react: declare @types/react as an optional peer dependency

1 participant