Skip to content

fix: import the React types the declarations annotate props with - #130

Merged
joshunrau merged 1 commit into
mainfrom
fix/declare-react-types-explicitly
Oct 30, 2026
Merged

joshunrau merged 1 commit into
mainfrom
fix/declare-react-types-explicitly

Conversation

@thomasbeaudry

Copy link
Copy Markdown
Collaborator

Problem

Since the components moved off forwardRef, props are annotated as React.ComponentProps<…>, and the emitted declarations carry that name unqualified. In 6.19.0, 47 .d.ts files in dist name React without importing it:

// dist/components/Checkbox/Checkbox.d.ts, as published in 6.19.0
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
export declare const Checkbox: ({ className, ref, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) => React.JSX.Element;

That resolves only for a consumer who has @types/react's UMD global in its program. A consumer whose React types are a plain module does not, and because the failure is inside a .d.ts under skipLibCheck, nothing reports it — every prop type silently becomes any.

Open Data Capture is such a consumer: it has no @types/react at all ("@types/react": "-" in its root pnpm.overrides), and its react is a vendored wrapper whose types never declare a global namespace. Bumping it from 6.16.1 to 6.19.0 produced 26 implicit-any errors across 12 files, none of them near a table or anything else that changed:

src/components/MailSettings/MailSettings.tsx(191,31): error TS7006: Parameter 'checked' implicitly has an 'any' type.
src/routes/_app/datahub/subjects/index.tsx(87,31): error TS7006: Parameter 'checked' implicitly has an 'any' type.
…

6.16.1 was unaffected: forwardRef made the emitted type import("react").ForwardRefExoticComponent<…>, an inline import that needs no global.

Change

import type React from 'react' in each of the 49 source files that names the type. The emitted declaration then imports it too, which resolves identically for every consumer:

// after
import type React from 'react';
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
export declare const Checkbox: ({ className, ref, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) => React.JSX.Element;

No file in dist names React unqualified now (47 → 0). Nothing but imports changed — no component, prop or runtime behaviour is touched.

Verification

  • pnpm lint clean, pnpm test 226/226, pnpm build clean.
  • Against the module-only React types that exposed this, a probe
    <Checkbox onCheckedChange={(checked) => …} /> fails on published 6.19.0 with TS7006 and type-checks against this build. Same tsconfig, same vendored React types, only the libui path differs.

Worth a release once merged — Open Data Capture is pinned to 6.16.1 behind a patch until a release carries both this and #129.

🤖 Generated with Claude Code

Since the components moved off `forwardRef`, their props are annotated as
`React.ComponentProps<...>` and the emitted declarations carry that name
unqualified: 47 of the `.d.ts` files in 6.19.0 name `React` without importing
it, so they resolve only for a consumer who happens to have the `@types/react`
UMD global loaded.

A consumer whose React types are a plain module does not. Open Data Capture is
one -- it has no `@types/react` at all (its `react` is a vendored wrapper whose
types never declare a global namespace), so every prop type degraded to `any`
and each handler parameter became an implicit-any error: 26 of them across 12
files on a bump from 6.16.1.

`import type React from 'react'` in each of the 49 source files that names the
type makes the emitted declaration import it too, which resolves the same way
for every consumer. No declaration in `dist` names `React` unqualified now.

Verified against the vendored, module-only React types that exposed this: a
probe calling `<Checkbox onCheckedChange={(checked) => ...} />` fails against
published 6.19.0 with TS7006 and type-checks against this build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@joshunrau
joshunrau merged commit b956eec into main Oct 30, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.19.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants