Skip to content

Rating component throws TS error Argument of type 'Element' is not assignable to parameter of type 'never' #95

Description

@farukumarx64

Description

The Rating component compiles and appears to work normally in development mode, but it fails during production build due to a TypeScript error.

In dev mode, the issue may not surface clearly (or may appear only as a type warning depending on tooling), but during next build / tsc --noEmit, the build fails.


Steps to Reproduce

  1. Import the Rating component:
import { Rating } from "reui";
  1. Use it normally:
<Rating rating={4} maxRating={5} />
  1. Run production build:
npm run build
# or
next build

Actual Behavior

Build fails with:

Argument of type 'Element' is not assignable to parameter of type 'never'

Dev vs Build Behavior

  • In development mode, the issue may not immediately block rendering
  • In some setups, it may only appear as a TypeScript warning
  • In production build (strict TS check), it becomes a hard failure and blocks compilation

Root Cause

Inside renderStars():

const stars = []
stars.push(<div>...</div>)

TypeScript infers:

const stars: never[]

Because:

  • The array is initialized empty
  • No explicit type is provided
  • Strict mode infers never[]
  • JSX elements cannot be assigned to never

Fix

Recommended fix:

const stars: JSX.Element[] = []

Alternative:

const stars: React.ReactNode[] = []

Suggested Improvement (optional refactor)

Instead of mutation:

const stars = Array.from({ length: maxRating }, (_, i) => {
  const star = i + 1

  return (
    <div key={star}>
      ...
    </div>
  )
})

This avoids type inference issues entirely and is more idiomatic React.


Impact

  • ❌ Blocks production builds in strict TypeScript setups
  • ⚠️ May go unnoticed in dev mode
  • 🚫 Affects adoption in modern frameworks (Next.js, Vite + strict TS, etc.)

Environment

  • React
  • TypeScript strict mode
  • Next.js / production build pipeline (tsc check enabled)

🙌 Contribution Note

Happy to contribute a fix PR if needed because this is a small but important typing issue that improves build reliability.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions