Skip to main content

StaticJsScalar

The union of all scalar (non-compound) sandbox values.

Import

import { type StaticJsScalar, isStaticJsScalar } from "@suntime-js/core";

Overview

StaticJsScalar covers all sandbox values that carry a single primitive host value. Each scalar type exposes that value through a .value property.

Scalars implement StaticJsPrimitive and are part of the StaticJsValue union.

Symbols

StaticJsSymbol is included in the scalar union because it is a primitive in JavaScript semantics. However, its interface also extends StaticJsObject to support Symbol.prototype method access inside the sandbox.

Member types

Type.value typeType guard
StaticJsStringstringisStaticJsString
StaticJsNumbernumberisStaticJsNumber
StaticJsBooleanbooleanisStaticJsBoolean
StaticJsNullnullisStaticJsNull
StaticJsUndefinedundefinedisStaticJsUndefined
StaticJsSymbolsymbolisStaticJsSymbol

Type guard

isStaticJsScalar(value)

isStaticJsScalar(value: StaticJsValue): value is StaticJsScalar

Returns true for any of the scalar member types above. Use this to branch before reading .value:

import { isStaticJsScalar } from "@suntime-js/core";

if (isStaticJsScalar(value)) {
console.log(value.value); // string | number | boolean | null | undefined | symbol
}