toObject

[ Function ]

public static toObject<T extends object>(
    value: any,
    defaultValue: T | null = null
): T | null;

Converts any compatible value to an object or array. If the parameter is already an object or an array, it is returned directly; if it is a string, it is converted into an object or array via JSON.parse.

Note: no type checking is performed during this process. This should be done downstream, for example via TcHmi.isSolidColor, Array.isArray or similar.

Parameter

Name

Type

Description

value

any

The value to convert.

Example: A JSON string.

defaultValue

any, null

This value is returned if the first parameter cannot be converted. Null applies if this parameter is not passed.

Return value

Type

Description

T, null

Returns an object/array or defaultValue or null in the event of an error.

toObject 1:

Available from 1.8