react-bits icon indicating copy to clipboard operation
react-bits copied to clipboard

TS variants of CardNav, PillNav, and MaskedHeading fail tsc --noEmit (ElementType dynamic components)

Open MauryaQbit opened this issue 1 month ago • 1 comments

Bug Report

Description

The TypeScript variants (src/ts-default and src/ts-tailwind) of CardNav, PillNav, and MaskedHeading do not type-check. Running tsc --noEmit against the repository (tsconfig includes src) reports 30 errors, all caused by dynamic element components typed as ElementType (linkComponent / tag) being used as JSX tags. Because the inferred element type has no children prop, TypeScript rejects children and other props.

Affected files:

  • src/ts-default/Components/CardNav/CardNav.tsx (and src/ts-tailwind/...)
  • src/ts-default/Components/PillNav/PillNav.tsx (and src/ts-tailwind/...)
  • src/ts-default/TextAnimations/MaskedHeading/MaskedHeading.tsx (and src/ts-tailwind/...)

Steps to Reproduce

  1. Clone the repository.
  2. Run npx tsc --noEmit (using the provided tsconfig.json).
  3. Observe 30 type errors, e.g.:
    src/ts-default/Components/CardNav/CardNav.tsx(466,8): error TS2745: This JSX tag's 'children' prop expects type 'never' which requires multiple children, but only a single child was provided.
    src/ts-default/TextAnimations/MaskedHeading/MaskedHeading.tsx(581,6): error TS2746: This JSX tag's 'children' prop expects a single child of type 'never', but multiple children were provided.
    

Root Cause

linkComponent is typed as ElementType (from React) and tag as ElementType. When used as <LinkComponent ...> / <Tag ...>, TypeScript resolves the element to a type whose children is never, so passing children (and in MaskedHeading, ref, className, style, etc.) fails.

Expected Behavior

The TS variants should pass tsc --noEmit cleanly. Typing the dynamic component as React.ComponentType<any> (or React.ElementType with an appropriate generic, e.g. React.ElementType<any>) and rendering with proper props would resolve the errors.

Environment

  • Node.js: current LTS
  • TypeScript: 5.7.3 (per package.json)
  • React: 19

Suggested Fix

  • In CardNav/PillNav: change linkComponent?: ElementType to linkComponent?: React.ComponentType<any> (or React.ElementType<any>), and cast usage accordingly.
  • In MaskedHeading: change tag?: ElementType similarly.

This keeps runtime behavior identical while making the TS variants type-check.

MauryaQbit avatar Oct 26 '26 12:10 MauryaQbit

Resolved in #1123. Verified the 30 reported errors on the previous main and a clean full npx tsc --noEmit after the fix. Both TypeScript variants of CardNav, PillNav, and MaskedHeading retain their existing public props and rendering behavior. The updated registry files are published in commit 66fd12b4.

DavidHDev avatar Nov 08 '26 14:11 DavidHDev