Reference · General

type_of

signature
type_of(any) -> str

What it does

The kind of a value as text: one of null, bool, int, float, dec, str, list, map, fn, html, response and error. In the browser a JavaScript Promise is promise, and a whole float is a float, as on the server: type_of(2.0) is float on both sides. It is the way to tell an int from a float, a decimal from a float, and an error value from anything else.

Examples

print(type_of(null), type_of(true), type_of(1), type_of(1.0), type_of(dec("1")), type_of("s"))print(type_of([]), type_of({}), type_of((x) => x), type_of(<p/>), type_of(err("x")))
output
null bool int float dec strlist map fn html error

Edge cases

print(type_of(1 / 2), type_of(4 / 2), type_of(1 + 1.0), type_of(dec("1") + 1))print(type_of(upper), type_of(redirect("/")), type_of(float("x")))print(json.parse("[1, 2.5, \"s\", null, true, {}]") | map(type_of))
output
float int float decfn response error["int", "float", "str", "null", "bool", "map"]

Errors

type_of never fails: every value has a kind, null included, and no argument at all is null.

print(type_of(), type_of(type_of))
output
null fn

Chaining

print(42 | type_of)print([1, "a", null, 2.5] | map(type_of) | unique)print(["1", 2, "3"] | filter((v) => type_of(v) == "str"))
output
int["int", "str", "null", "float"]["1", "3"]

See also

is_err, int, float, str, len

Thread
9Useful? Like it, or add to its thread below.

Thread 0 posts

On type_of(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo