-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript "'className' is missing in props validation" despite being defined #3284
Comments
Seems like |
I have the same problem
Versions
|
It seems weird to me, but this workaround, using an interface and extending DetailedHTMLAttributes, seems to work: interface InputProps extends React.DetailedHTMLProps<
React.InputHTMLAttributes<HTMLInputElement>,
HTMLInputElement
> {}
export const Input = (
props: InputProps
) => (
// your code
); |
Still broken in 7.33.2 |
@rwb196884 its not broken, it’s just not something we support yet. |
If you import directly from React the error message goes away. Works: import type { HTMLAttributes } from "react"
import { cn } from "../../lib/utils"
export function Heading({ className, ...props }: HTMLAttributes<HTMLDivElement>) {
return <div className={cn("font-semibold text-lg", className)} {...props} />
} Does not work: import React from "react"
import { cn } from "../../lib/utils"
export function Heading({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return <div className={cn("font-semibold text-lg", className)} {...props} />
} |
Our prop types are fine, but eslint-react isn't detecting them correctly. With a little help jsx-eslint/eslint-plugin-react#3284 (comment) we can tell it what the props are.
@divmgl I found the same issue and workaround but I'm completely puzzled about why does that behave that way. Isn't it supposed to import the exact same thing? If you (or anyone) know/s the reason this import behaves like this, I'd like to learn why. Cause right now, seeing this, to me Javascript became broken. What I'm missing? Do they import different things just because the same thing is imported in different ways? To be completely clear, I'm referring to this: import type { HTMLAttributes } from "react"
// ...
export function Heading({ className, ...props }: HTMLAttributes<HTMLDivElement>) { versus this: import React from "react"
// ...
export function Heading({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) { |
I agree that this is a bug; I merely posted the workaround. |
I have this issue with shadci generated components , like here: const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => (
<TabsPrimitive.List
ref={ref}
className={cn(
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground',
className,
)}
{...props}
/>
)); gives: |
Still happens with Alert Dialog on the latest version (7.34.4). const AlertDialogOverlay = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
>(({ className, ...props }, ref) => ( // 'className' is missing in props validation eslint[react/prop-types]
<AlertDialogPrimitive.Overlay
{...props}
ref={ref}
/>
)) |
@KirillTregubov if AlertDialogPrimitive isn't defined in that file, then there's no practical way for eslint to know that |
Description
I am observing
'className' is missing in props validation
despite it being correctly specified in the type definition.React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>
React.HTMLAttributes<HTMLInputElement>.className?: string | undefined
Versions
Example
Expected behaviour
The
eslint-disable-next-line
should not be necessary.I can also workaround this by adding in
& { className?: string }
into the type definition of props.The text was updated successfully, but these errors were encountered: