I faced the following error when I send the remaining props, (...props) to a <div> element. I tried several solutions but didn't succeed.
React.createElement
with casting?
Error:(35, 10) TS2322: Type '{ children: ReactNode; defaultChecked?: boolean | undefined; defaultValue?: string | number | readonly string[] | undefined; suppressContentEditableWarning?: boolean | undefined; ... 249 more ...; onTransitionEndCapture?: ((event: TransitionEvent<...>) => void) | undefined; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'.
Type '{ children: ReactNode; defaultChecked?: boolean | undefined; defaultValue?: string | number | readonly string[] | undefined; suppressContentEditableWarning?: boolean | undefined; ... 249 more ...; onTransitionEndCapture?: ((event: TransitionEvent<...>) => void) | undefined; }' is not assignable to type 'HTMLAttributes<HTMLDivElement>'.
Types of property ''aria-relevant'' are incompatible.
Type '"text" | "additions" | "additions removals" | "additions text" | "all" | "removals" | "removals additions" | "removals text" | "text additions" | "text removals" | undefined' is not assignable to type '"text" | "additions" | "additions text" | "all" | "removals" | undefined'.
Type '"additions removals"' is not assignable to type '"text" | "additions" | "additions text" | "all" | "removals" | undefined'.
The code:
import React, {FunctionComponent} from 'react';
import classNames from 'classnames';
type Direction = 'row' | 'column';
interface FlexProps extends React.HTMLAttributes<HTMLDivElement> {
direction?: Direction;
reverse?: boolean;
inline?: boolean;
}
const Flex: FunctionComponent<FlexProps> = (
{
direction = 'row',
reverse = false,
inline = false,
...props
}: FlexProps
): JSX.Element => {
const flex: string = inline ? 'inline-flex' : 'flex';
const directionReverse: string = [
'flex',
direction,
reverse && 'reverse'
].join('-');
const className: string = classNames(
flex,
directionReverse,
props.className
);
return (
<div className={className} {...props}>
{props.children}
</div>
);
};
I have already tried with:
DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
<Flex>Test</Flex>)<Flex aria-relevant="additions removals">