-
Notifications
You must be signed in to change notification settings - Fork 1
The Types
Typit contains a number of built-in types that describe primitive types (strings
, booleans
, numbers
, etc), common type bounds (void
, never
, etc), as well as type 'concepts' (unknown
, not-present
, etc).
This page serves as an overview of all of these built-in types and their functions/general use cases.
For more information on any of the types specified on this page, links will also be present to go to the more in-depth reference material for each type.
The StandardType
class enumerates the types of the regular primitive types found in JavaScript/TypeScript.
Numeric values conform to this type:
StandardType.NUMBER.checkConformity(5); // true
Non-numeric values do not:
StandardType.NUMBER.checkConformity("goober"); // false
StandardType.NUMBER.checkConformity("11"); // false
StandardType.NUMBER.checkConformity(true); // false
StandardType.NUMBER.checkConformity({ key: 42 }); // false
Note that the NaN
('not a number') value is technically actually a numeric value:
StandardType.NUMBER.checkConformity(NaN); // true
If you need to additionally check that a given value is not NaN
you can just check directly against it:
if (value === NaN) { /* Handle NaN value. */ }
Boolean values (true
and false
) conform to this type:
StandardType.BOOLEAN.checkConformity(true); // true
StandardType.BOOLEAN.checkConformity(false); // true
Non-boolean values do not:
StandardType.BOOLEAN.checkConformity("booger"); // false
StandardType.BOOLEAN.checkConformity("true"); // false
StandardType.BOOLEAN.checkConformity(1711); // false
StandardType.BOOLEAN.checkConformity({ key: "wee" }); // false
String value conform to this type:
StandardType.STRING.checkConformity("Hello, world!"); // true
StandardType.STRING.checkConformity(""); // true
StandardType.STRING.checkConformity("09182734"); // true
Non-string values do not:
StandardType.STRING.checkConformity(41210); // false
StandardType.STRING.checkConformity(false); // false
StandardType.STRING.checkConformity([ 1, 2, 3, 'a', 'b', 'c' ]); // false
StandardType.STRING.checkConformity({ key: "bar" }); // false
Description.
Content.
Content.
Content.
Content.
Content.
Content.