Skip to main content

isFormNode()

Checks whether an unknown value is a node created by this instance of Form Nodes.

Signature

import { isFormNode } from '@ngblocks/form-nodes';

isFormNode(value: unknown): value is AnyNode

Parameter and return value

value accepts any value, including null and undefined. The result is a boolean type guard: when true, TypeScript narrows the argument to AnyNode. It does not infer a particular node kind, child structure, or value type. Use $api for common state and operations after narrowing, because direct child names may shadow API members.

Example

is-form-node.example.ts
import { signal } from '@angular/core';
import { field, form, isFormNode } from '@ngblocks/form-nodes';

const profile = form({ name: field('Marco') });

isFormNode(profile); // true
isFormNode(profile.name); // true
isFormNode(signal('Marco')); // false
isFormNode({ name: 'Marco' }); // false

const candidate: unknown = profile.name;
if (isFormNode(candidate)) {
candidate(); // 'Marco'
if (candidate() !== 'Marco') {
throw new Error('The narrowed node must retain its committed value.');
}
}

if (!isFormNode(candidate) || !isFormNode(profile) || isFormNode(signal('Marco')) || isFormNode({ name: 'Marco' })) {
throw new Error('Only Form Nodes nodes should pass the type guard.');
}

The helper can also be passed directly to an array's filter() method to obtain AnyNode[].

Recognized values

ValueResult
Nodes created by field(), form(), group(), or array()true
Nested nodes and nodes from configured primitivestrue
Detached nodestrue
Plain objects, ordinary functions, null, or undefinedfalse
Ordinary Angular signalsfalse
A node's callable $apifalse
Nodes from a separately loaded copy of the libraryfalse

The check reads an internal marker. It does not call the supplied value, read node state, or establish signal dependencies, and it works outside Angular injection contexts.

The marker belongs to the loaded package instance. This is a node-identity check, not structural validation or a check that a node is currently attached to a form or binding.