API Reference / @gtkx/runtime / toVariant
Variable: toVariant
consttoVariant: <S>(typeString,value) =>GLib.Variant
Defined in: packages/runtime/dist/variant.d.ts:72
Packs a JavaScript value into the GLib.Variant a GVariant type string describes, building the nested arrays, dictionaries, tuples and maybes the type calls for. A type string given as a literal also types value, so "as" takes an array of strings, "a{sv}" a record of variants, "(si)" a string and a number pair, and a 64-bit type a bigint.
Type Parameters
S
S extends string
Parameters
typeString
S
GVariant type of the variant to build, such as "a{sv}".
value
VariantValue<S>
Value to pack, shaped the way typeString describes.
Returns
GLib.Variant
The packed variant.
Throws
When the type string is not one complete GVariant type, or when a value packed as an object path or a type signature is not a valid one.