Skip to main content
Version: 4.3

InferElement

type InferElement<Cells> = Extract<CellArrayMember<Cells>, {
type: typeof ELEMENT_MODEL_TYPE;
}>;

Infer the element record type from a cells collection, typically typeof cells. Selects the member whose type is 'element', so a mixed array narrows to its element variant with the inferred data shape. Compose with Computed for reading hooks, or index ['data'] for the render-data type.

Custom shapes (a type other than 'element') are excluded, type the record union manually for those, as documented on CellRecord.

Type Parameters

Type ParameterDescription
Cellsthe cells collection to infer from, usually typeof cells

Example

import type { InferElement } from '@joint/react';

const cells = [
{ id: 'a', type: 'element', data: { label: 'A' } },
{ id: 'e', type: 'link', source: { id: 'a' }, target: { id: 'b' }, data: { weight: 2 } },
] as const;

type Node = InferElement<typeof cells>; // element variant of the union
type NodeData = InferElement<typeof cells>['data']; // { label: 'A' }

Stay in the know

Be where thousands of diagramming enthusiasts meet

Star us on GitHub