The isElementOfType util is not currently providing the 2nd generic arg to ReactElement. This results in certain cases failing to narrow types which is the whole point of the type guard.
export function isElementOfType<T>(
node: ReactNode,
type: T
): node is ReactElement<InferComponentProps<T>> {
return isValidElement(node) && node.type === type;
}
We should be able to fix this by constraining T a bit more and then passing it as the 2nd arg.
export function isElementOfType<
T extends string | JSXElementConstructor<any> =
| string
| JSXElementConstructor<any>,
>(node: ReactNode, type: T): node is ReactElement<InferComponentProps<T>, T> {
return isValidElement(node) && node.type === type;
}
The
isElementOfTypeutil is not currently providing the 2nd generic arg toReactElement. This results in certain cases failing to narrow types which is the whole point of the type guard.We should be able to fix this by constraining T a bit more and then passing it as the 2nd arg.