Type Notes

1 min read

Runtime type inspection and conversion.

Type inspection

NoteSignatureReturns
typeOfv"string" "map" "slice" "number" "bool" "null"
typeMapvbool
typeListvbool
typeStringvbool
typeNumbervbool
typeBoolvbool
typeNullvbool
lenvint — element count for maps/slices, char count for strings
isEmptyvbool
isScalarvbool (string, number, bool, null)
isCompositevbool (map, slice)

Type conversion

NoteSignatureReturns
toIntvint64 — truncates floats, parses strings, 1/0 for bools
toFloatvfloat64
toBoolvbool"true"/"yes"/"1" → true, "false"/"no"/"0" → false
toStringvstring

Examples

# Expose input format in status
- path: scheduleFormat
  value: "{{ typeOf .spec.schedule }}"

# Branch on type in onReconcile (Approach B — no normalize)
when:
  - field: spec.schedule
    operator: typeOf
    value: map

# Validate a field is a map
- field: spec.config
  operator: custom
  value: "{{ typeMap .spec.config }}"
  message: "spec.config must be a structured object"
  action: deny

# Arithmetic on a field that may arrive as a string
replicas: "{{ toInt .spec.replicas }}"

For field-shape coercion (parsing JSON/YAML strings back to maps or lists), see type coercion notes.