Js
The Js module mostly contains ReScript bindings to standard JavaScript APIs like console.log, or the JavaScript String, Date, and Promise classes.
It is meant as a zero-abstraction interop layer and directly exposes JavaScript functions as they are. If you can find your API in this module, prefer this over an equivalent Belt helper. For example, prefer Js.Array2 over Belt.Array
Argument Order
For historical reasons, some APIs in the Js namespace (e.g. Js.String) are using the data-last argument order whereas others (e.g. Js.Date) are using data-first.
For more information about these argument orders and the trade-offs between them, see this blog post.
Eventually, all modules in the Js namespace are going to be migrated to data-first though.
Js.Xxx2 Modules
Prefer Js.Array2 over Js.Array, Js.String2 over Js.String, etc. The latters are old modules.
t
Deprecated
This has been deprecated and will be removed in v13. Use the {..} type directly instead.
type t<'a> = 'a
constraint 'a = {..}JS object type
globalThis
Deprecated
let globalThis: t<{..}>JS global object reference
null
Deprecated
@unboxed
type null<'a> = Js_null.t<'a> = Value('a) | @as(null) Nullundefined
Deprecated
This has been deprecated and will be removed in v13.
type undefined<'a> = Js_undefined.t<'a>nullable
Deprecated
@unboxed
type nullable<'a> = Js_null_undefined.t<'a> =
| Value('a)
| @as(null) Null
| @as(undefined) Undefinednull_undefined
Deprecated
type null_undefined<'a> = nullable<'a>toOption
let toOption: nullable<'a> => option<'a>undefinedToOption
Deprecated
let undefinedToOption: undefined<'a> => option<'a>nullToOption
Deprecated
let nullToOption: null<'a> => option<'a>isNullable
Deprecated
let isNullable: nullable<'a> => boolimport
Deprecated
let import: 'a => promise<'a>testAny
Deprecated
let testAny: 'a => boolThe same as {!test} except that it is more permissive on the types of input
promise
Deprecated
This is deprecated and will be removed in v13. Use the promise type directly instead.
type promise<+'a, +'e>The promise type, defined here for interoperation across packages.
null
Deprecated
let null: null<'a>The same as empty in Js.Null. Compiles to null.
undefined
Deprecated
let undefined: undefined<'a>The same as empty Js.Undefined. Compiles to undefined.
typeof
Deprecated
let typeof: 'a => stringtypeof x will be compiled as typeof x in JS. Please consider functions in
Js.Types for a type safe way of reflection.
log
Deprecated
let log: 'a => unitEquivalent to console.log any value.
log2
Deprecated
let log2: ('a, 'b) => unitlog3
Deprecated
let log3: ('a, 'b, 'c) => unitlog4
Deprecated
let log4: ('a, 'b, 'c, 'd) => unitlogMany
Deprecated
let logMany: array<'a> => unitA convenience function to console.log more than 4 arguments
eqNull
Deprecated
let eqNull: ('a, null<'a>) => booleqUndefined
Deprecated
let eqUndefined: ('a, undefined<'a>) => booleqNullable
Deprecated
let eqNullable: ('a, nullable<'a>) => boolunsafe_lt
Deprecated
let unsafe_lt: ('a, 'a) => boolunsafe_lt(a, b) will be compiled as a < b.
It is marked as unsafe, since it is impossible
to give a proper semantics for comparision which applies to any type
unsafe_le
Deprecated
let unsafe_le: ('a, 'a) => boolunsafe_le(a, b) will be compiled as a <= b.
See also Js.unsafe_lt.
unsafe_gt
Deprecated
let unsafe_gt: ('a, 'a) => boolunsafe_gt(a, b) will be compiled as a > b.
See also Js.unsafe_lt.
unsafe_ge
Deprecated
let unsafe_ge: ('a, 'a) => boolunsafe_ge(a, b) will be compiled as a >= b.
See also Js.unsafe_lt.