./src/components/ui/badge.tsx:45:9
Type error: Object literal may only specify known properties, and '"data-component"' does not exist in type 'WithBaseUIEvent<DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>> | ((otherProps: WithBaseUIEvent<...>) => WithBaseUIEvent<...>)'.
43 | props: mergeProps<"span">(
44 | {
> 45 | "data-component": "Badge",
| ^
46 | className: cn(badgeVariants({ variant }), className),
47 | },
48 | props
Next.js build worker exited with code: 1 and signal: null
make: *** [build] Error 1
Assistant
The user has a TypeScript error in their badge component. Let me first read the OVERVIEW.md as required by the rules, then look at the badge.tsx file to understand the issue.
The issue is that mergeProps<"span"> expects props that match DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, but data-component is not a recognized property in that type.
The problem is that mergeProps has a generic type parameter and it doesn't allow arbitrary data-* attributes in its type definition. Even though data-* attributes are valid HTML, the TypeScript typing for mergeProps from @base-ui/react doesn't seem to accept them.
Let me look at how other components in this project handle data-component to understand the pattern better.
Assistant
@base-ui/react のバージョンと mergeProps の型定義を確認させてください。
The issue is that mergeProps<"span"> from has strict typing that doesn't allow attributes in the first argument object literal. The problem is specifically with how TypeScript infers the type of the object literal passed to .
Assistant
useRender の型定義も確認します。
Now I understand the issue. mergeProps<"span"> expects each argument to be of type InputProps<"span"> which is PropsOf<"span"> | ((otherProps: PropsOf<"span">) => PropsOf<"span">) | undefined. And PropsOf<"span"> is WithBaseUIEvent<React.ComponentPropsWithRef<"span">>.
The issue is that React.ComponentPropsWithRef<"span"> which is React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, and when you pass an object literal, TypeScript enforces excess property checking. The data-* attributes ARE supported in JSX, but they're supported via a special rule in JSX syntax, not via the TypeScript type system.
When you use data-* as a property in a plain object literal (not in JSX), TypeScript doesn't know about them. I have a few options to fix this: I could use a type assertion to bypass the excess property checking, remove the from the call and add it separately, or assign the props to a variable first to avoid the strict checking. Let me think through which approach is cleanest.
Now I see the key insight. Looking at line 48 of useRender.d.ts:
typescript
props?: Record<string, unknown> | undefined;
The props parameter in useRender accepts Record<string, unknown>, which is very flexible and would accept data-component. The issue is that this props goes through mergeProps<"span">() first, and mergeProps has stricter typing.
The fix is simple: since useRender accepts Record<string, unknown> for props, we can either:
User
code
./src/components/ui/badge.tsx:45:9
Type error: Object literal may only specify known properties, and '"data-component"' does not exist in type 'WithBaseUIEvent<DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>> | ((otherProps: WithBaseUIEvent<...>) => WithBaseUIEvent<...>)'.
43 | props: mergeProps<"span">(
44 | {
> 45 | "data-component": "Badge",
| ^
46 | className: cn(badgeVariants({ variant }), className),
47 | },
48 | props
Next.js build worker exited with code: 1 and signal: null
make: *** [build] Error 1
Cast the object to include data-component (e.g., using as any or a more specific cast)
Move data-component outside of mergeProps and apply it differently
Use a type assertion on the first argument
Let me look at how useRender and mergeProps work. The issue is that mergeProps<"span"> expects WithBaseUIEvent<DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>> which doesn't include data-* attributes.
I'm realizing that data-* attributes should normally be allowed by React's typing, so this might be a specific limitation in how mergeProps defines its type overloads. Looking at the error message more closely, it seems the first argument to mergeProps has a narrower type definition than I'd expect, which is preventing the data-component attribute from being recognized.
The core issue is that while React's JSX namespace does support data-* attributes, when you pass an object literal directly to a function expecting HTMLAttributes, TypeScript enforces strict excess property checking and rejects any properties it doesn't explicitly know about. The simplest solution would be to separate the data attributes or cast the object to bypass the type checking. Still writing type solutions... I'm realizing the badge component was probably simplified from the original shadcn version when it was adapted to use useRender and mergeProps, which introduced this typing conflict. The cleanest fix would be to either pass data-component outside the merge or just use a type assertion, so let me look at what the original implementation looked like to decide the best approach. Still writing the component...
Actually, I think the real issue is that mergeProps has stricter typing than what we're passing in. A type assertion on the object literal should resolve this cleanly without restructuring the whole function.
But let me reconsider whether using useRender is even necessary here—I could simplify this by just returning a standard JSX element with the data-component attribute, which would sidestep the typing issue entirely and keep the component more straightforward.
data-component
mergeProps
A type assertion seems like the most straightforward solution here. Even though React.ComponentPropsWithRef<"span"> doesn't explicitly include data-component, casting the object with as will let me bypass the type checking without requiring the source type to match perfectly. Still writing the type assertion...
Actually, I'm realizing useRender takes props and returns a JSX element, so I can't tack on attributes afterward. Let me reconsider whether I should handle data-component through the props passed to useRender or find another way to attach it to the rendered output.
Skip mergeProps and merge manually: but we lose the event handler merging behavior
Move data-component out of mergeProps: Merge the base-ui props first, then add data-component separately
Type assertion on the mergeProps argument: Use as to bypass excess property checking
The cleanest approach is to move data-component out of mergeProps and into the final props object. I'm spreading the mergeProps result and adding data-component on top, which should work since useRender.props accepts Record<string, unknown>. The mergeProps return type is PropsOf<"span"> which spreads fine into an object literal. I could also remove the CustomBadgeProps interface since it's no longer needed.
Implement the plan as specified, it is attached for your reference. Do NOT edit the plan file itself.
To-do's from the plan have already been created. Do not create them again. Mark them as in_progress as you work, starting with the first one. Don't stop until you have completed all the to-dos.