Contact Us 1-800-596-4880

typeOf

typeOf<T>(value: T): Type<T>

Returns the primitive data type of a value, such as String.

A value’s type is taken from its runtime representation and is never one of the arithmetic types (intersection, union, Any, or Nothing) nor a type alias. If present, metadata of a value is included in the result of typeOf (see metadataOf).

Parameters

Name Description

value

Input value to evaluate.

Example

This example identifies the type of several input values.

Source

%dw 2.0
output application/json
---
[ typeOf("A b"), typeOf([1,2]), typeOf(34), typeOf(true), typeOf({ a : 5 }) ]

Output

[ "String", "Array", "Number", "Boolean", "Object" ]

Example

This example shows that the type of a value is independent of the type with which it is declared.

Source

%dw 2.0
output application/json

var x: String | Number = "clearly a string"
var y: "because" = "because"
---
[typeOf(x), typeOf(y)]

Output

["String", "String"]