Skip to content

Fix forwardRef no-props + CSSProperties/ReactNode widening (co-install @types/react)#6

Merged
jagguji merged 1 commit into
mainfrom
fix-react-types-resolution
Jun 9, 2026
Merged

Fix forwardRef no-props + CSSProperties/ReactNode widening (co-install @types/react)#6
jagguji merged 1 commit into
mainfrom
fix-react-types-resolution

Conversation

@jagguji

@jagguji jagguji commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

The bug (one root cause, three symptoms)

Component packages do import React from "react" and type their props via React.ForwardRefExoticComponent<P>, React.CSSProperties, React.ReactNode, React.MouseEvent, … But the scratch installer only fetched the target packagereact is a peer dependency, so @types/react was never installed. Every React.* type then collapsed to any/unknown, causing:

  • 🔴 forwardRef components extract ZERO propsModal: React.ForwardRefExoticComponent<ModalProps & RefAttributes> resolved to ForwardRefExoticComponent<any> (no call signatures, no recoverable type args), so the whole component emitted empty (Modal(no-props)). Same for @smastrom/react-rating.
  • 🟡 React.CSSProperties → broken string instead of JsxDOM.style.
  • 🟡 React.ReactNode → broken string instead of React.element.

The fix

Co-install React's type definitions in the same scratch npm install command:

npm install --no-save <pkg> react react-dom @types/react @types/react-dom

(resolve.mjs.) One line; no API change.

Verified end-to-end

Package Before After
react-responsive-modal Modal(no-props) (skipped) 26 props, compiles clean (0 err/warn)
react-day-picker 0 usable / 2 broken 27 components, 27 usable, 0 brokenstyle → JsxDOM.style, modifiersStyles → Dict.t<JsxDOM.style>, footer → React.element

No regression: npm test (smoke + 13 golden) and npm run test:compile green. (Goldens use inline stubs, so they don't exercise the scratch installer — this path is verified via the real packages above.)

…eact.* types resolve

Component packages do `import React from "react"` and type props via
`React.ForwardRefExoticComponent<P>`, `React.CSSProperties`, `React.ReactNode`, etc.
The scratch installer only fetched the target package (react is a peer dep), so
`@types/react` was absent and every `React.*` type collapsed to `any`/`unknown`:
forwardRef components extracted ZERO props (whole components emitted empty), and
`CSSProperties`/`ReactNode` widened to a `string` placeholder.

Co-install `react react-dom @types/react @types/react-dom` in the same scratch
`npm install` command. Verified end-to-end:
- react-responsive-modal: 0 props (skipped "no-props") → 26 props, compiles clean.
- react-day-picker: 0 usable / 2 broken → 27 components, 27 usable, 0 broken
  (style → JsxDOM.style, modifiersStyles → Dict.t<JsxDOM.style>, footer → React.element).
@jagguji jagguji merged commit 35a2c9b into main Jun 9, 2026
5 checks passed
@jagguji jagguji deleted the fix-react-types-resolution branch June 9, 2026 13:55
jagguji added a commit that referenced this pull request Jun 9, 2026
Adds per-PR/commit **preview builds of the tool itself** via
[pkg.pr.new](https://pkg.pr.new), mirroring blend's
[#1358](juspay/blend-design-system#1358) but
adapted for this repo (npm, single package, no build step).

## What it does
A new `preview` job in `ci.yml` (gated on the smoke + golden tests
passing) runs `npx pkg-pr-new publish` on every PR and every push to
`main`. The bot posts a sticky PR comment with an install URL:

```bash
npm i https://pkg.pr.new/@juspay/rescript-bindgen@<sha>
```

## Why
Right now, testing an unreleased fix means using local source or `npm
link`. With previews, anyone can `npm i` the **exact build** of a
PR/commit into another project and run `npx rescript-bindgen …` — no
clone, no link, no waiting for a real release. (This is exactly the gap
we hit testing the @types/react fix.)

Previews live on pkg.pr.new's domain (not npmjs.org), are commit-pinned
and ephemeral, and **don't** touch `latest`/`beta`.

## Setup
The [pkg-pr-new GitHub App](https://github.com/apps/pkg-pr-new) is
already installed on the repo (no token to manage). `PUBLISHING.md`
documents the preview flow.

## Notes
- Packs per the package's existing `files` allowlist (src/, types.d.ts,
README, …), so the preview ships the working CLI.
- No build step needed (pure ESM).
- Branched off the latest `main` (includes #4/#5/#6); tests green.
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.

1 participant