mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
36 lines
883 B
TypeScript
Executable File
36 lines
883 B
TypeScript
Executable File
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
|
|
import React from "react";
|
|
import { isObject } from "./type-narrowing";
|
|
|
|
// ref: https://changelog.com/posts/the-react-reactnode-type-is-a-black-hole
|
|
|
|
export type StrictReactFragment =
|
|
| {
|
|
key?: string | number | null;
|
|
ref?: null;
|
|
props?: {
|
|
children?: StrictReactNode;
|
|
};
|
|
};
|
|
|
|
export type StrictReactNode =
|
|
| React.ReactElement
|
|
| React.ReactText
|
|
| StrictReactFragment
|
|
| React.ReactPortal
|
|
| Iterable<StrictReactNode>
|
|
| boolean
|
|
| null
|
|
| undefined;
|
|
|
|
export function isReactNode(node: unknown): node is StrictReactNode {
|
|
return (isObject(node) && React.isValidElement(node))
|
|
|| Array.isArray(node) && node.every(isReactNode)
|
|
|| node == null
|
|
|| typeof node !== "object";
|
|
}
|