Skip to Content

isNode()

GitHub上的源代码 

测试一个对象是否可以作为Node使用。在 TypeScript 中,如果返回 true,这是一种类型保护,它将把你传入的任何内容的类型缩小为Node

🌐 Test whether an object is usable as a Node. In TypeScript this is a type guard that will narrow the type of whatever you pass in to Node if it returns true.

import { isNode } from '@xyflow/react'; const node = { id: 'node-a', data: { label: 'node', }, position: { x: 0, y: 0, }, }; if (isNode(node)) { // .. }

签名

🌐 Signature

Parameters:
NameTypeDefault
elementunknown

The element to test.

Returns:
boolean

Tests whether the provided value can be used as a Node. If you’re using TypeScript, this function acts as a type guard and will narrow the type of the value to Node if it returns true.

Last updated on