diff --git a/src/Core__Type.resi b/src/Core__Type.resi index f2707a08..8bfe4bdf 100644 --- a/src/Core__Type.resi +++ b/src/Core__Type.resi @@ -1,12 +1,62 @@ +/*** +Utilities for classifying the type of JavaScript values at runtime. +*/ + +/** +The possible types of JavaScript values. +*/ type t = [#undefined | #object | #boolean | #number | #bigint | #string | #symbol | #function] +/** +`typeof(someValue)` + +Returns the underlying JavaScript type of any runtime value. + +See [`typeof`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) on MDN. + +## Examples +```rescript +Console.log(Type.typeof("Hello")) // Logs "string" to the console. + +let someVariable = true + +switch someVariable->Type.typeof { +| #boolean => Console.log("This is a bool, yay!") +| _ => Console.log("Oh, not a bool sadly...") +} +``` +*/ external typeof: 'a => t = "#typeof" module Classify: { + /*** + Classifies JavaScript runtime values. + */ + + /** + An abstract type representing a JavaScript function. + + See [`function`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) on MDN. + */ type function + + /** + An abstract type representing a JavaScript object. + + See [`object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) on MDN. + */ type object + + /** + An abstract type representing a JavaScript symbol. + + See [`symbol`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) on MDN. + */ type symbol + /** + The type representing a classified JavaScript value. + */ type t = | Bool(bool) | Null @@ -17,5 +67,17 @@ module Classify: { | Function(function) | Symbol(symbol) + /** +`classify(anyValue)` +Classifies a JavaScript value. + +## Examples +```rescript +switch %raw(`null`)->Type.Classify.classify { +| Null => Console.log("Yup, that's null.") +| _ => Console.log("This doesn't actually appear to be null...") +} +``` +*/ let classify: 'a => t }