Skip to content

Module Js.Types

Utility functions for runtime reflection on JS types

ocaml
type symbol
reasonml
type symbol;

Js symbol type only available in ES6

ocaml
type bigint_val
reasonml
type bigint_val;

Js bigint type only available in ES2020

ocaml
type obj_val
reasonml
type obj_val;
ocaml
type undefined_val
reasonml
type undefined_val;

This type has only one value undefined

ocaml
type null_val
reasonml
type null_val;

This type has only one value null

ocaml
type function_val
reasonml
type function_val;
ocaml
type _ t = 
  | Undefined : undefined_val t
  | Null : null_val t
  | Boolean : bool t
  | Number : float t
  | String : string t
  | Function : function_val t
  | Object : obj_val t
  | Symbol : symbol t
  | BigInt : bigint_val t
reasonml
type t(_) = 
  | Undefined : t(undefined_val)
  | Null : t(null_val)
  | Boolean : t(bool)
  | Number : t(float)
  | String : t(string)
  | Function : t(function_val)
  | Object : t(obj_val)
  | Symbol : t(symbol)
  | BigInt : t(bigint_val)
;
ocaml
val test : 'a -> 'b t -> bool
reasonml
let test: 'a => t('b) => bool;
ocaml
test "x" String = true
reasonml
test("x", String) == true;
ocaml
type tagged_t = 
  | JSFalse
  | JSTrue
  | JSNull
  | JSUndefined
  | JSNumber of float
  | JSString of string
  | JSFunction of function_val
  | JSObject of obj_val
  | JSSymbol of symbol
  | JSBigInt of bigint_val
reasonml
type tagged_t = 
  | JSFalse
  | JSTrue
  | JSNull
  | JSUndefined
  | JSNumber(float)
  | JSString(string)
  | JSFunction(function_val)
  | JSObject(obj_val)
  | JSSymbol(symbol)
  | JSBigInt(bigint_val)
;
ocaml
val classify : 'a -> tagged_t
reasonml
let classify: 'a => tagged_t;