{"id":25596845,"url":"https://github.com/nanoporetech/ts-runtime-typecheck","last_synced_at":"2025-04-13T02:31:01.690Z","repository":{"id":40738848,"uuid":"303400296","full_name":"nanoporetech/ts-runtime-typecheck","owner":"nanoporetech","description":"A collection of common types for TypeScript along with dynamic type cast methods.","archived":false,"fork":false,"pushed_at":"2023-01-08T14:01:58.000Z","size":401,"stargazers_count":9,"open_issues_count":10,"forks_count":0,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-06T08:02:15.826Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nanoporetech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-12T13:26:39.000Z","updated_at":"2022-06-26T22:01:18.000Z","dependencies_parsed_at":"2023-02-08T06:16:33.824Z","dependency_job_id":null,"html_url":"https://github.com/nanoporetech/ts-runtime-typecheck","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fts-runtime-typecheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fts-runtime-typecheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fts-runtime-typecheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanoporetech%2Fts-runtime-typecheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanoporetech","download_url":"https://codeload.github.com/nanoporetech/ts-runtime-typecheck/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657795,"owners_count":21140841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-21T12:34:45.306Z","updated_at":"2025-04-13T02:31:01.639Z","avatar_url":"https://github.com/nanoporetech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-runtime-typecheck\n\n![100% coverage](https://img.shields.io/badge/coverage-100%25-success)\n![0 dependencies](https://img.shields.io/badge/dependencies-0-success)\n![npm](https://img.shields.io/npm/dm/ts-runtime-typecheck)\n\nSimple functions for validating complex data.\n\nJavaScript is a very flexible language. Meaning it's easy to get tripped up by a value with an unexpected type. Even in TypeScript you occasionally have to deal with values which cannot be safely typed at compile time. This library provides a comprehensive selection of functions to simplify type checking code with clear and concise function calls. Ensuring strict type safety throughout your program, no matter the input.\n\n## Installation\n\nReleases are available on the npm repository and our GitHub releases page. ESM and CJS formats are both included, as well as TypeScript type definition files. Both formats work without TypeScript if you prefer plain JS.\n\n```bash\nnpm install ts-runtime-typecheck\n```\n\n---\n\n## Contents\n\n- [Installation](#installation)\n- [Type Casts](#type-casts)\n- [Type Checks](#type-checks)\n- [Type Coerce](#type-coerce)\n- [Type Asserts](#type-asserts)\n- [JSON Types](#json-types)\n- [Ensuring an optional value is defined](#ensuring-an-optional-value-is-defined)\n- [Array/Object of Type Casts](#arrayobject-of-type-casts)\n- [Validating interfaces](#validating-interfaces)\n- [Union types](#union-types)\n- [Class instances](#class-instances)\n- [Guarded functions](#guarded-functions)\n- [Reference](#reference)\n- [Changelog](#changelog)\n\n## Type Casts\n\n**Type Casts** take an `unknown` value as an argument, and return a typed value as the result. These functions take the form [`as{TYPE}`](#reference-type-casts), for example [`asNumber`](#asNumber). If the input value does not match the required type the function will throw. This does not perform any coercion on the value, passing a `string` of a number to [`asNumber`](#asNumber) will cause it to throw.\n\n```typescript\nimport { asNumber } from 'ts-runtime-typecheck';\n\nfunction square (input: unknown): number {\n  const value: number = asNumber(input);\n  return value * value;\n}\n\nsquare(10)\n// 100\nsquare()\n// Error: Unable to cast undefined to number\nsquare('10')\n// Error: Unable to cast string to number\n```\n\n**Type Casts** are meant to primarily validate questionable values that are expected to be in a well defined structure. Such as network responses, interfacing with untyped JavaScript or reading data back from a file. If you are looking to validate a type, without throwing an error then take a look at [Type Checks](#type-checks).\n\n### Optional Type Casts\n\nIn the situation you want to check a value meets an [`Optional`](#optional) type there exists an alternate function for each type cast. These take the form [`asOpt{TYPE}`](#reference-optional-type-casts). Unlike the standard functions when a [`Nullish`](#nullish) value is passed in they will emit `undefined` instead of throwing. If the input is not [`Nullish`](#nullish), then it behaves the same as the standard type casts. If the type condition is met then it emits the value, otherwise it will throw.\n\n---\n\n## Type Checks\n\n**Type Checks** take an `unknown` value as an argument, and return a `boolean` indicating if the given value matches the required type. These functions take the form [`is{TYPE}`](#reference-type-checks). In the correct situation TypeScript is capable of refining the type of a value through the use of these functions and flow analysis, like the below example.\n\n```typescript\nimport { isNumber } from 'ts-runtime-typecheck';\n\nexport function printSq (value: unknown) {\n  if (isNumber(value)) {\n    // inside this block `value` is a `number`\n    console.log(`${value} * ${value} = ${value * value}`);\n  }\n  else {\n    // inside this block `value` is `unknown`\n    console.log('Invalid input', value);\n  }\n}\n```\n\nIn addition all relevant [Type Checks](#reference-type-checks) have an alternate variant that take the form [`isOpt{TYPE}`](#reference-optional-type-checks). These variants return true if the value meets the given type or [`Nullish`](#nullish).\n\n```typescript\nimport { isOptNumber } from 'ts-runtime-typecheck';\n\nexport function printSq (input: unknown) {\n  if (isOptNumber(input)) {\n    // inside this block `input` is `number | undefined | null`\n    const value = input ?? 1; // use nullish coalescing operator to ensure value is number\n    console.log(`${value} * ${value} = ${value * value}`);\n  }\n  else {\n    // inside this block `input` is `unknown`\n    console.log('Invalid input', value);\n  }\n}\n```\n\n---\n\n## Type Coerce\n\n**Type Coercion** functions take an `unknown` value as an argument, and convert it into a specific type. These functions take the format [`make{TYPE}`](#reference-type-coerce). Unlike the other functions this only works for small subset of types: number, string and boolean. They make a best effort to convert the type, but if the input is not suitable then they will throw an error. For instance passing a non-numeric string to [`makeNumber`](#make-number) will cause it to throw, as will passing a string that is not `\"true\" | \"false\"` to [`makeBoolean`](#make-boolean). While these functions will take any input value, this is to allow the input of values that have not been validated. The only valid input types for all 3 functions are `number | string | boolean`. The intention here is to allow useful conversion, but prevent accidentally passing complex types.\n\nThere is an argument that [`makeString`](#makestring) could support using the `toString` method of an `object`, but the default `toString` method returns the useless `[object Object]` string. It is possible to detect if an object has implemented it's own `toString` method, but is it correct to use it in this situation? That depends on the intention of the programmer. In the absence of a clear answer the line has been drawn at only accepting primitives.\n\n```typescript\nimport { makeNumber } from 'ts-runtime-typecheck';\n\nmakeNumber('80') // 80\nmakeNumber(80) // 80\nmakeNumber(true) // 1\nmakeNumber(false) // 0\nmakeNumber('hello') // Error: Unable to cast string to Number\nmakeNumber({\n  toString () { return 'hello' }\n}) // Error: Unable to cast object to Number\n\n```\n\n---\n\n## Type Asserts\n\n**Type Assert** functions accept an `unknown` value and throw if the value does not meet the type requirement, they do not return a value. While this may seem very similar to [Type Casts](#type-casts) they are capable of providing a hint to the TypeScript compiler without needing to reassign the value. As such they are very helpful for validating function arguments before using them.\n\nEach type assert takes an optional second argument that is a label for the passed value, this will be included in the thrown `TypeAssertion` error if the value does not meet the type requirement, making it easier to isolate the type violation.\n\n```typescript\nimport { assertDefined } from 'ts-runtime-typecheck';\n\nfunction main (meaningOfLife: Optional\u003cnumber\u003e) {\n  meaningOfLife // number | null | undefined\n  assertDefined(meaningOfLife, 'Meaning of Life');\n  meaningOfLife // number\n  return 'but what is the question?';\n}\n\nmain(42); // 'but what is the question?'\nmain(); // TypeAssertion: Meaning of Life is not defined\n```\n\nTypeAsserts cannot be based on generic types, due to limits in the TypeScript type system. Hence there is no analogous function to [`isStruct`](#isstruct) and similar [`TypeCheck`](#typecheck). However, there is an alternative. It's possible to utilise an invariant ( or assert) function with a [`TypeCheck`](#typecheck) to get the same effect, and an implementation of [`invariant`](#invariant) is provided for this purpose.\n\n```typescript\nimport { invariant, isLiteral } from 'ts-runtime-typecheck';\n\nfunction main (meaningOfLife: unknown) {\n  meaningOfLife // unknown\n  invariant(isLiteral(42)(meaningOfLife), \"Universe is broken, meaning of life isn't 42!\");\n  meaningOfLife // 42\n  return 'but what is the question?';\n}\n\nmain(42); // 'but what is the question?'\nmain(); // TypeAssertion: Universe is broken, meaning of life isn't 42!\n```\n\n---\n\n## JSON Types\n\nDealing with validating JSON values can often be frustrating, so to make it a little easier JSON specific types and checks are provided. Using the [`JSONValue`](#jsonvalue) type in your code will ensure that TS statically analyses any literal values as serializable to JSON.\n\n```typescript\nimport type { JSONArray, JSONObject, JSONValue } from 'ts-runtime-typecheck';\n\n// JSONArray is an Array of JSONValues\nconst a: JSONArray = [12, 'hello'];\n// JSONObject is a Dictionary of JSONValues\nconst b: JSONObject = {\n  num: 12,\n  str: 'hello'\n};\n// JSONValue can be any of the following: JSONObject, JSONArray, string, number, boolean or null\nconst c: JSONValue = 12;\n\nconst d: JSONValue = new Error('hi'); // Type 'Error' is not assignable to type 'JSONValue'\n```\n\nFor dynamic data [`isJSONValue`](#isjsonvalue) and [`asJSONValue`](#asjsonvalue) provide recursive type validation on a value.\n\n[Type Check](#reference-type-checks) and [Type Casts](#reference-type-casts) are provided for [`JSONArrays`](#jsonarray) and [`JSONObjects`](#jsonobject), with the caveat that they only accept [`JSONValues`](#jsonvalue). This is to avoid needing to recursively validate values which have already been validated.\n\n```typescript\nimport { asJSONValue, isJSONObject, isJSONArray } from 'ts-runtime-typecheck';\nimport type { JSONValue } from 'ts-runtime-typecheck';\n\nfunction main (a: unknown) {\n  const obj: JSONValue =  asJSONValue(a);\n  // obj: JSONValue\n  if (isJSONArray(obj)) {\n    // obj: JSONArray\n  }\n  else if (isJSONObject(obj)) {\n    // obj: JSONObject\n  }\n  else {\n    // obj: number | string | boolean | null\n  }\n}\n```\n\nOne other caveat of [`JSONValue`](#jsonvalue) is that it does not guarantee that the value is not cyclic. It is not possible to serialize cyclic object with `JSON.stringify`, but they are otherwise valid. Using [`isJSONValue`](#isjsonvalue) or [`asJSONValue`](#asjsonvalue) on a cyclic object *will fail*.\n\n```typescript\nimport { asJSONValue } from 'ts-runtime-typecheck';\nimport type { Dictionary } from 'ts-runtime-typecheck';\n\nconst almost_right: Dictionary = {};\nalmost_right.self = almost_right;\n\n// BANG! this will fail, it recurses endlessly\nconst obj = asJSONValue(almost_right);\n```\n\n---\n\n## Ensuring an optional value is defined\n\nA common situation is that you have an [`Optional`](#optional) value, with a well defined type. At a specific time it should be defined, but the type system is not aware of this. TypeScript will allow you to cast the value to a non-optional type using `!`, but this is often discouraged in style guides. A safer alternative is to use [`asDefined`](#asdefined) and friends, which can be used to subtract the optionality from the type.\n\n```typescript\nimport { asDefined, assertDefined, isDefined } from 'ts-runtime-typecheck';\n\nfunction doThing (value: number) {\n  // [...]\n}\n\nfunction branching (value?: number) {\n  // used for conditions, allows for an alternative to throwing or custom error behavior\n  if (isDefined(value)) {\n    doThing(value)\n  } else {\n    console.log('bad things')\n  }\n}\n\nfunction inline (value?: number) {\n  // used inline, throws if the value is Nullish otherwise returns the value\n  doThing(asDefined(value))\n}\n\nfunction assertion (value?: number) {\n  // used to ensure execution doesn't progress if the value isn't defined, throws if the value is Nullish\n  assertDefined(value)\n  doThing(value)\n}\n```\n\n## Array/Object of Type Casts\n\nValidating that a value is an array or dictionary is easy enough, but how about the type of the contents? [`asArrayOf`](#asarrayof) and [`asDictionaryOf`](#asdictionaryof) allow you to cast the elements of a collection using a user defined [Type Check](#reference-type-checks). For example, to cast to `Array\u003cstring\u003e`:\n\n```typescript\nimport { isString, asArrayOf } from 'ts-runtime-typecheck';\n\nfunction main (obj: unknown) {\n  const asStringArray = asArrayOf(isString);\n\n  const arr: string[] = asArrayOfString(obj);\n}\n```\n\nOr `Array\u003cDictionary\u003cnumber\u003e\u003e`:\n\n```typescript\nimport { isNumber, isDictionaryOf, asArrayOf } from 'ts-runtime-typecheck';\n\nfunction main () {\n  const isDictionaryOfNumber = isDictionaryOf(isNumber);\n  const asArrayOfDictionaryOfNumber = asArrayOf(isDictionaryOfNumber);\n\n  const arr = asArrayOfDictionaryOfNumber([\n    {\n      a: 12,\n      b: 42\n    },\n    {\n      n: 90\n    }\n  ]);\n}\n\n```\n\n## Validating interfaces\n\nValidating the shape of an object using a combination of [`asDictionary`](#asdictionary) and other [Type Casts](#reference-type-casts) specific to property types can be a bit verbose. To simplify this scenario you can use [`asStruct`](#asstruct). This function takes an [`InterfacePattern`](#interfacepattern) that defines a specific structure and returns a new function that will cast an unknown value to that structure. An [`InterfacePattern`](#interfacepattern) is a fancy name for a [`Dictionary`](#dictionary) of [Type Checks](#reference-type-checks).\n\n```typescript\nimport { asStruct, isString, isNumber } from 'ts-runtime-typecheck';\n\ninterface Item {\n  name: string;\n  value: number;\n}\n\nconst asItem = asStruct({ name: isString, value: isNumber })\n\nfunction main (obj: unknown) {\n  const item: Item = asItem(obj);\n\n  console.log(`${item.name} = ${item.value}`);\n}\n```\n\nThere is also a [Type Check](#reference-type-checks) variant of the this function called [`isStruct`](#isstruct) which works in a very similar way. As an [`InterfacePattern`](#interfacepattern) is composed of [Type Check](#reference-type-checks) functions it's possible to compose nested interface [Type Checks](#reference-type-checks).\n\n```typescript\nimport { asStruct, isStruct, isString, isOptString, isNumber } from 'ts-runtime-typecheck';\nimport type { Optional } from 'ts-runtime-typecheck';\n\ninterface Declaration {\n  item: Item;\n  description: Optional\u003cstring\u003e\n}\n\ninterface Item {\n  name: string;\n  value: number;\n}\n\nconst isItem = isStruct({ name: isString, value: isNumber });\nconst asDeclaration = asStruct({ item: isItem, description: isOptString });\n\nfunction main (obj: unknown) {\n  const { item, description } = asDeclaration(obj);\n\n  const comment: string = description ? `// ${description}` : '';\n  console.log(`${item.name} = ${item.value} ${comment}`);\n}\n```\n\n---\n\n## Union types\n\nWhen a value can be 2 or more types it is relatively easy to do [Type Check](#reference-type-checks).\n\n```typescript\nimport { isString, isArray } from 'ts-runtime-typecheck';\n\nif (isString(a) || isArray(a)) {\n  // a: string | unknown[]\n}\n```\n\nBut you can't cast to that type, or pass it into a function like [`asArrayOf`](#asarrayof) or [`isStruct`](isstruct) which require a [Type Check](#reference-type-checks) for their input. To do this you can use [`isUnion`](#isunion) or [`asUnion`](#asunion). These functions take a variable number of [Type Checks](#reference-type-checks) and produce a union of them.\n\n```typescript\nimport {\n  isString,\n  isArray,\n  isUnion,\n  asArrayOf\n} from 'ts-runtime-typecheck';\n\nconst check = asArrayOf(isUnion(isString, isArray));\nconst b = check(['hello', [0, 1, 2], 'world']);\n```\n\n---\n\n## Class instances\n\nUnder most scenarios you will know if a value is an instance of a given class. However, there are scenarios where this is not the case. For these situations you can use [`isInstance`](#isinstance) or [`asInstance`](#asinstance) to ensure you have the correct type.\n\n```typescript\nimport { isInstance } from 'ts-runtime-typecheck';\n\nfunction print_error (err) {\n  if (isInstance(Error)(err)) {\n    print_string(err.message);\n  } else {\n    print_unknown(err)\n  }\n}\n```\n\nWhen validating a value matches an interface it may be desirable to instead use [`isInstance`](#isinstance) instead of [`isStruct`](#isstruct). While it doesn't provide the same guarantees it will often be significantly faster, as it does not perform a [Type Check](#reference-type-checks) on each member to see that they exist and contain the right type of value.\n\n---\n\n## Literal types\n\nTypeScript supports value types for [`Primitive`](#primitive)s. For example\n\n```typescript\nlet a: 'hello world' = 'hello world';\n\na = 'goodbye world'; // Type '\"goodbye world\"' is not assignable to type '\"hello world\"'\n```\n\nYou can use [`asLiteral`](#asliteral) and [`isLiteral`](#isliteral) to construct [`TypeCast`](#typecast)s and [`TypeCheck`](#typecheck)s respectively for these value types. These checks can be particularly useful for discriminated unions.\n\n```typescript\ninterface A {\n  type: 'a';\n  value: number;\n}\n\ninterface B {\n  type: 'b';\n  value: number;\n}\n\nconst isA = isStruct({\n  type: isLiteral('a'),\n  value: isNumber,\n});\n\nfunction main (n: A | B) {\n  n // A | B\n  if (isA(n)) {\n    n // A\n  } else {\n    n // B\n  }\n}\n```\n\n---\n\n## Guarded Functions\n\nTypeScript provides excellent compile time protections against misusing functions. The number of parameters, the types of parameters and the return type of the function are all statically type checked. But it provides no *runtime* protections. In a pure TS project this isn't normally required, but sometimes you need to pass around abstract functions and have them behave reliably. Alternatively you could be authoring a library and want to ensure that developers using your library without TS use your functions correctly. In both these scenarios you can wrap the function using `asGuardedFunction`, specifying the return and parameter types. This will return a new function that when called will validate the incoming arguments, and the outgoing return value at runtime. If the types don't match up it will throw an error. The resulting function will have accurate parameter and return types, irrespective of the original function.\n\n```typescript\n\nimport { asGuardedFunction } from 'ts-runtime-typecheck';\n\nexport const publicFunction = asGuardedFunction(\n  (a: number, b: number) =\u003e `${(a / b) * 100}%`, // function to wrap\n  isString, // return value\n  isNumber, isNumber // parameters\n);\n```\n\n---\n\n## Reference\n\n### Reference: Type Casts\n\n- ### asString\n\n  Cast `unknown` to `string`.\n\n- ### asNumber\n\n  Cast `unknown` to `number`.\n\n- ### asIndex\n\n  Cast `unknown` to [`Index`](#index).\n\n- ### asPrimitive\n\n  Cast `unknown` to [`Primitive`](#primitive).\n\n- ### asIndexable\n\n  Cast `unknown` to [`Indexable`](#indexable).\n\n- ### asBoolean\n\n  Cast `unknown` to `boolean`.\n\n- ### asArray\n\n  Cast `unknown` to `Array\u003cunknown\u003e`.\n\n- ### asDictionary\n\n  Cast `unknown` to [`Dictionary\u003cunknown\u003e`](#dictionary).\n\n- ### asFunction\n\n  Cast `unknown` to [`UnknownFunction`](#unknownfunction).\n\n- ### asDefined\n\n  Cast [`Type | Nullish`](#nullish) to `Type`, where `Type` is a generic parameter.\n\n- ### asJSONValue\n\n  Cast `unknown` to [`JSONValue`](#jsonvalue). This function recursively validates the value, and hence will fail if given a cyclic value.\n\n- ### asJSONObject\n\n  Cast [`JSONValue`](#jsonvalue) to [`JSONObject`](#jsonobject). Unlike [`asJSONValue`](#asjsonvalue) this does not perform recursive validation, hence it only accepts a [`JSONValue`](#jsonvalue) so that the sub-elements are of a known type.\n\n- ### asJSONArray\n  \n  Cast [`JSONValue`](#jsonvalue) to [`JSONArray`](#jsonarray). Unlike [`asJSONValue`](#asjsonvalue) this does not perform recursive validation, hence it only accepts a [`JSONValue`](#jsonvalue) so that the sub-elements are of a known type.\n\n- ### asArrayOf\n  \n  Takes a Type Cast function for `Type` and returns a new Type Cast function for `Array\u003cType\u003e` where type is a generic parameter. Refer to [Array/Object of Type Casts](#arrayobject-of-type-casts) for examples.\n\n- ### asDictionaryOf\n  \n  Takes a Type Cast function for `Type` and returns a new Type Cast function for [`Dictionary\u003cType\u003e`](#dictionary) where type is a generic parameter. Refer to [Array/Object of Type Casts](#arrayobject-of-type-casts) for examples.\n\n- ### asStruct\n  \n  Takes an [`InterfacePattern`](#interfacepattern) which is equivalent to `Type` and returns a new Type Cast function for `Type`, where `Type` is an interface defined by the [`TypeChecks`](#typecheck) specified in the pattern. Refer to [Validating interfaces](#validating-interfaces) for examples.\n\n- ### asInstance\n\n  Takes a class (not a instance of a class) and returns a new Type Cast for an instance of that class.\n\n- ### asLiteral\n\n  Takes a [Primitive](#primitive) value and returns a new Type Cast for that specific value.\n\n- ### asGuardedFunction\n\n  Takes a unknown value and a series of [`TypeChecks`](#typecheck) and returns a strongly typed function. It will be a new function that wraps the original with runtime type validation, ensuring that the arguments and return value are the expected types. The first [`TypeCheck`](#typecheck) is for the return value, and subsequent variadic [`TypeChecks`](#typecheck) are used for validating arguments.\n\n### Reference: Optional Type Casts\n\n- ### asOptString\n\n  Cast `unknown` value to `string | undefined`. If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptNumber\n\n  Cast `unknown` value to `number | undefined`. If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptIndex\n\n  Cast `unknown` value to [`Index | undefined`](#index). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptPrimitive\n\n  Cast `unknown` value to [`Primitive | undefined`](#primitive). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptIndexable\n\n  Cast `unknown` value to [`Indexable | undefined`](#indexable). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptBoolean\n\n  Cast `unknown` value to `boolean | undefined`. If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptArray\n\n  Cast `unknown` value to `Array\u003cunknown\u003e | undefined`. If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptDictionary\n\n  Cast `unknown` value to [`Dictionary\u003cunknown\u003e | undefined`](#dictionary). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptFunction\n\n  Cast `unknown` value to [`UnknownFunction | undefined`](#unknownfunction). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asUnion\n\n  Takes a variable number of type checks as parameters `\u003cA\u003e(...checks: TypeCheck\u003cA\u003e[])` and returns a new type cast that composes them into type cast for the union `A`. This allows creating a cast for a type union by composing any existing type checks.\n\n- ### asOptUnion\n\n  Identical to [`asUnion`](#asunion) but it the resulting cast returns `A | null | undefined`.\n\n- ### asOptJSONValue\n\n  Cast `unknown` value to [`JSONValue | undefined`](#jsonvalue). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptJSONObject\n\n  Cast [`JSONValue | undefined`](#jsonvalue) value to [`JSONObject | undefined`](#jsonobject). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptJSONArray\n\n  Cast [`JSONValue | undefined`](#jsonvalue) value to [`JSONArray | undefined`](#jsonarray). If value is [`Nullish`](#nullish) then return `undefined`.\n\n- ### asOptArrayOf\n\n  Takes a Type Cast function for `Type` and returns a new Type Cast function for `Array\u003cType\u003e | undefined` where type is a generic parameter. Refer to [Array/Object of Type Casts](#arrayobject-of-type-casts) for examples.\n\n- ### asOptDictionaryOf\n\n  Takes a Type Cast function for `Type` and returns a new Type Cast function for [`Dictionary\u003cType\u003e | undefined`](#dictionary) where type is a generic parameter. Refer to [Array/Object of Type Casts](#arrayobject-of-type-casts) for examples.\n\n- ### asOptStruct\n  \n  Takes an [`InterfacePattern`](#interfacepattern) which is equivalent to `Type` and returns a new Type Cast function for `Type | undefined`, where `Type` is an interface defined by the [`TypeAsserts`](#typeassert) specified in the pattern. Refer to [Validating interfaces](#validating-interfaces) for examples.\n\n- ### asOptInstance\n\n  Takes a class (not a instance of a class) and returns a new Type Cast for a Optional instance of that class.\n\n- ### asOptLiteral\n\n  Takes a [Primitive](#primitive) value and returns a new optional Type Cast for that specific value.\n\n### Reference: Type Checks\n\n- ### isDictionary\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Dictionary\u003cunknown\u003e`](#dictionary).\n\n- ### isFunction\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`UnknownFunction`](#unknownfunction).\n\n- ### isBoolean\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `boolean`.\n\n- ### isString\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `string`.\n\n- ### isNumber\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `number`.\n\n- ### isIndex\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Index`](#index).\n\n- ### isPrimitive\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Primitive`](#primitive).\n\n- ### isIndexable\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Indexable`](#indexable).\n\n- ### isArray\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `Array\u003cunknown\u003e`.\n\n- ### isUndefined\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `undefined`.\n\n- ### isNullish\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Nullish`](#nullish).\n\n- ### isDefined\n\n  Takes an `unknown` value and returns a boolean indicating if the value is **not** of the type [`Nullish`](#nullish).\n\n- ### isUnion\n\n  Takes a variable number of type checks as parameters `\u003cA\u003e(...checks: TypeCheck\u003cA\u003e[])` and returns a new type check that composes them into union type check `TypeCheck\u003cA\u003e`. This allows creating a test for a type union by composing any existing type checks. For inline code it will generally make sense to use logical OR operators instead of this, for example `if ( isNumber(n) || isArray(n) ) {}`. This particular function is intended for when you wish to compose a type check or cast that contains a union, or create a library type check for a common union type.\n\n- ### isJSONValue\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`JSONValue`](#jsonvalue).\n\n- ### isJSONArray\n\n  Takes an [`JSONValue`](#jsonvalue) value and returns a boolean indicating if the value is of the type [`JSONArray`](#jsonarray).\n\n- ### isJSONObject\n\n  Takes an [`JSONValue`](#jsonvalue) value and returns a boolean indicating if the value is of the type [`JSONObject`](#jsonobject).\n\n- ### isArrayOf\n  \n  Takes a Type Check function for `Type` and returns a new Type Check function for `Array\u003cType\u003e` where Type is a generic parameter.\n\n- ### isDictionaryOf\n  \n  Takes a Type Check function for `Type` and returns a new Type Check function for [`Dictionary\u003cType\u003e`](#dictionary) where Type is a generic parameter.\n\n- ### isStruct\n\n  Takes an [`InterfacePattern`](#interfacepattern) which is equivalent to `Type` and returns a new [`TypeAssert`](#typeassert) function for `Type`, where `Type` is an interface defined by the [`TypeAsserts`](#typeassert) specified in the pattern. Refer to [Validating interfaces](#validating-interfaces) for examples.\n\n- ### isInstance\n\n  Takes a class (not a instance of a class) and returns a new Type Check for an instance of that class.\n\n- ### isLiteral\n\n  Takes a [Primitive](#primitive) value and returns a new Type Check for that specific value.\n\n### Reference: Optional Type Checks\n\n- ### isOptDictionary\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Optional\u003cDictionary\u003cunknown\u003e\u003e`](#dictionary).\n\n- ### isOptFunction\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Optional\u003cUnknownFunction\u003e`](#unknownfunction).\n\n- ### isOptBoolean\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `Optional\u003cboolean\u003e`.\n\n- ### isOptString\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `Optional\u003cstring\u003e`.\n\n- ### isOptNumber\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `Optional\u003cnumber\u003e`.\n\n- ### isOptPrimitive\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Optional\u003cPrimitive\u003e`](#primitive).\n\n- ### isOptIndex\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Optional\u003cIndex\u003e`](#index).\n\n- ### isOptIndexable\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Optional\u003cIndexable\u003e`](#indexable).\n\n- ### isOptArray\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type `Optional\u003cArray\u003cunknown\u003e\u003e`.\n\n- ### isOptUnion\n\n  Identical to [`isUnion`](#isunion) but it the resulting typecheck is `TypeCheck\u003cA | null | undefined\u003e`.\n\n- ### isOptJSONValue\n\n  Takes an `unknown` value and returns a boolean indicating if the value is of the type [`Optional\u003cJSONValue\u003e`](#jsonvalue).\n\n- ### isOptJSONArray\n\n  Takes an [`Optional\u003cJSONValue\u003e`](#jsonvalue) value and returns a boolean indicating if the value is of the type [`Optional\u003cJSONArray\u003e`](#jsonarray).\n\n- ### isOptJSONObject\n\n  Takes an [`Optional\u003cJSONValue\u003e`](#jsonvalue) value and returns a boolean indicating if the value is of the type [`Optional\u003cJSONObject\u003e`](#jsonobject).\n\n- ### isOptStruct\n\n  Takes an [`InterfacePattern`](#interfacepattern) which is equivalent to `Type` and returns a new [`TypeAssert`](#typeassert) function for `Optional\u003cType\u003e`, where `Type` is an interface defined by the [`TypeAsserts`](#typeassert) specified in the pattern. Refer to [Validating interfaces](#validating-interfaces) for examples.\n\n- ### isOptArrayOf\n  \n  Takes a Type Check function for `Type` and returns a new Type Check function for `Optional\u003cArray\u003cType\u003e\u003e` where Type is a generic parameter.\n\n- ### isOptDictionaryOf\n  \n  Takes a Type Check function for `Type` and returns a new Type Check function for [`Optional\u003cDictionary\u003cType\u003e\u003e`](#dictionary) where Type is a generic parameter.\n\n- ### isOptInstance\n\n  Takes a class (not a instance of a class) and returns a new Type Check for a Optional instance of that class.\n\n- ### isOptLiteral\n\n  Takes a [Primitive](#primitive) value and returns a new optional Type Check for that specific value.\n\n### Reference: Type Coerce\n\n- ### makeString\n\n  Takes an `unknown` value and converts it to it's *textual* representation. A value that cannot be cleanly converted will trigger an error.\n\n- ### makeNumber\n\n  Takes an `unknown` value and converts it to it's *numerical* representation. A value that cannot be cleanly converted will trigger an error.\n\n- ### makeBoolean\n\n  Takes an `unknown` value and converts it to it's *boolean* representation. A value that cannot be cleanly converted will trigger an error.\n\n- ### makeStrictPartial\n\n  Takes a value of the generic type `T` and returns a copy of the object excluding any members that were `Nullish`. The returned object meets the type `StrictPartial\u003cT\u003e`.\n\n### Reference: Type Assert\n\n- ### assertDefined\n\nAssert value of type [`Type | Nullish`](#nullish) is `Type`, where `Type` is a generic parameter. Accepts an optional name for the value that is included in the error if the value is nullish.\n\n- ### assertNumber\n\nAssert value of type `unknown` is `number`. Accepts an optional name for the value that is included in the error if the value is not a number.\n\n- ### assertString\n\nAssert value of type `unknown` is `string`. Accepts an optional name for the value that is included in the error if the value is not a `string`.\n\n- ### assertBoolean\n\nAssert value of type `unknown` is `boolean`. Accepts an optional name for the value that is included in the error if the value is not a `boolean`.\n\n- ### assertIndex\n\nAssert value of type `unknown` is `Index`. Accepts an optional name for the value that is included in the error if the value is not a `Index`.\n\n- ### assertPrimitive\n\nAssert value of type `unknown` is `Primitive`. Accepts an optional name for the value that is included in the error if the value is not a `Primitive`.\n\n- ### assertArray\n\nAssert value of type `unknown` is `unknown[]`. Accepts an optional name for the value that is included in the error if the value is not a `unknown[]`.\n\n- ### assertDictionary\n\nAssert value of type `unknown` is `Dictionary`. Accepts an optional name for the value that is included in the error if the value is not a `Dictionary`.\n\n- ### assertIndexable\n\nAssert value of type `unknown` is `Indexable`. Accepts an optional name for the value that is included in the error if the value is not a `Indexable`.\n\n- ### assertFunction\n\nAssert value of type `unknown` is `UnknownFunction`. Accepts an optional name for the value that is included in the error if the value is not a `UnknownFunction`.\n\n- ### assertOptNumber\n\nAssert value of type `unknown` is `Optional\u003cnumber\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cnumber\u003e`.\n\n- ### assertOptString\n\nAssert value of type `unknown` is `Optional\u003cstring\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cstring\u003e`.\n\n- ### assertOptBoolean\n\nAssert value of type `unknown` is `Optional\u003cboolean\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cboolean\u003e`.\n\n- ### assertOptIndex\n\nAssert value of type `unknown` is `Optional\u003cIndex\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cIndex\u003e`.\n\n- ### assertOptPrimitive\n\nAssert value of type `unknown` is `Optional\u003cPrimitive\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cPrimitive\u003e`.\n\n- ### assertOptArray\n\nAssert value of type `unknown` is `Optional\u003cunknown[]\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cunknown[]\u003e`.\n\n- ### assertOptDictionary\n\nAssert value of type `unknown` is `Optional\u003cDictionary\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cDictionary\u003e`.\n\n- ### assertOptIndexable\n\nAssert value of type `unknown` is `Optional\u003cIndexable\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cIndexable\u003e`.\n\n- ### assertOptFunction\n\nAssert value of type `unknown` is `Optional\u003cUnknownFunction\u003e`. Accepts an optional name for the value that is included in the error if the value is not a `Optional\u003cUnknownFunction\u003e`.\n\n- ### assertJSONValue\n\nAssert value of type `unknown` is `JSONValue`. Accepts an optional name for the value that is included in the error if the value is not a `JSONValue`.\n\n- ### assertJSONArray\n\nAssert value of type `JSONValue` is `JSONArray`. Accepts an optional name for the value that is included in the error if the value is not a `JSONArray`.\n\n- ### assertJSONObject\n\nAssert value of type `JSONValue` is `JSONObject`. Accepts an optional name for the value that is included in the error if the value is not a `JSONObject`.\n\n- ### assertOptJSONValue\n\nAssert value of type `unknown` is `JSONValue | undefined`. Accepts an optional name for the value that is included in the error if the value is not a `JSONValue | undefined`.\n\n- ### assertOptJSONArray\n\nAssert value of type `JSONValue | undefined` is `JSONArray | undefined`. Accepts an optional name for the value that is included in the error if the value is not a `JSONArray | undefined`.\n\n- ### assertOptJSONObject\n\nAssert value of type `JSONValue | undefined` is `JSONObject | undefined`. Accepts an optional name for the value that is included in the error if the value is not a `JSONObject | undefined`.\n\n### Reference: Helper functions\n\n- ### invariant\n\n  An invariant is a logical declaration about a condition which the programmer knows to be true, but the compiler cannot. Many of the patterns in ts-runtime-typecheck are based around this concept, albeit to encourage a stricter and safer environment. This helper accepts a logical condition and a message. If the condition is true nothing happens, if it's false then a [`TypeAssertion`](#typeassertion) is thrown with the given message. If the condition is the result of a [`TypeCheck`](#typecheck) then the type predicate is enforced by the invariant.\n  \n  ```typescript\n  import { invariant, isString } from 'ts-runtime-typecheck';\n\n  function main (username: unknown) {\n    invariant(isString(username), 'Expected username to be a string');\n\n    username // string\n  }\n  ```\n\n- ### inspectType\n\nInspects the type of a given value and returns a description of it as a string. Useful for constructing debug messages from unknown values. Instances of classes are described using the name of their class. Abstract objects are traversed recursively so that their elements can be described as well. Recursion uses a depth limit to prevent overlarge descriptions. Once the limit has been reached abstract objects will be described as `Dictionary`.\n\nAn optional second argument can be passed to modify the default behaviour. For example you can change the `maxDepth` limit from it's default of `3`; a value of `0` would prevent recursion whereas `Infinity` would remove the limit.\n\nArrays currently do not feature recursive type description, but this might be introduced in future.\n\nInternally this is used to describe values in type error messages.\n\n```typescript\nimport { inspectType } from 'ts-runtime-typecheck';\n\nclass Example {}\n\ninspectType('hello world'); // string\ninspectType(null) // null\ninspectType([]) // Array\ninspectType(new Example) // Example\ninspectType({}) // {}\ninspectType({\n  foo: 'hello',\n  bar: 'world'\n}) // { foo: string, bar: string }\ninspectType({ foo: 'bar' }, { maxDepth: 0 }); // Dictionary\n```\n\n### Reference: Types\n\n- ### JSONValue\n\n  A union of all the JSON compatible types: [`JSONArray`](#jsonarray), [`JSONObject`](#jsonobject), `number`, `string`, `boolean`, `null`.\n\n- ### JSONObject\n\n  An alias to `Dictionary\u003cJSONValue\u003e` which can represent any JSON `Object` value.\n\n- ### JSONArray\n\n  An alias to `Array\u003cJSONValue\u003e` which can represent any JSON `Array` value.\n\n- ### Dictionary\n\n  An alias to `Record\u003cstring, Type\u003e` where `Type` is a generic parameter that default to `unknown`. This type can be used to represent a typical key-value map constructed from a JS `Object`. Where possible use [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instead, as it is specifically designed for this purpose and has better protection against null errors in TS.\n\n- ### Index\n\n  A union of the `number` and `string` types that represent a value that could be used to index an element within a JS `Object`.\n\n- ### Primitive\n\n  A union of the `number`, `string` and `boolean` types that are the key primitive values in JS.\n\n- ### Indexable\n\n  An alias to `Record\u003cIndex, Type\u003e` where `Type` is a generic parameter that default to `unknown`. This type can be used to represent an unknown key-value object that can be indexed using a `number` *or* `string`. It is intended to be used to ease the transition of JS project to TS. Where possible use [`Dictionary`](#dictionary) or preferably [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instead, as it is specifically designed for this purpose and has better protection against null errors in TS.\n\n- ### Nullish\n\n  A union of `undefined` and `null`. Generally preferable to either `null` or `undefined` on non-validated input. However, be aware of varying behavior between these 2 types in JS around optional members, default parameters and equality.\n\n- ### Optional\n\n  A union of `Type` and [`Nullish`](#nullish) where `Type` is a generic parameter.\n\n- ### UnknownFunction\n\n  A stricter alternative to the type `Function`. It accepts any number of unknown parameters, and returns an unknown value. Allowing you to reference an untyped function in a slightly safer manner. This does not provide any arity or type checks for the parameters.\n\n- ### UnknownAsyncFunction\n\n  Identical to [`UnknownFunction`](#unknownfunction) in all ways but 1, it returns `Promise\u003cunknown\u003e` instead.\n\n- ### TypeCheck\n\n  An alias for a function that meets the requirements of TypeScript [Type Guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards). They take the format `(value: unknown) =\u003e value is TYPE`. With the exception of specialist JSON checks all [TypeChecks](#reference-type-checks) conform to this type.\n\n- ### InterfacePattern\n\n  An alias for a [`Dictionary`](#dictionary) of [`TypeAssert`](#typeassert) functions. When used in conjunction with [`isStruct`](#isstruct) or [`asStruct`](#asstruct) they can  validate an `object` against the equivalent interface to the pattern.\n\n- ### StrictRequired\n\n  A variant of the inbuilt `Required\u003cT\u003e`, which is the opposite of `Optional\u003cT\u003e` in that it subtracts the type `undefined` from each member of the type `T`. StrictRequired varies in that it also subtracts the type `null` from each member. Ensuring that all members meet the constraint `NonNullable`.\n\n- ### StrictPartial\n\n  A variant of the `Partial\u003cT\u003e` inbuilt, and closely related to `FuzzyPartial`. `Partial` makes no guarantees about the members of the type `T`, as such they can be unions of `null`. This can introduce inconsistency for users of the type; expecting that members can be specified using either `null` or `undefined`, where only some can also use `null`. `StrictPartial` resolves this by specifying that no members of the type `T` can be `null`, ensuring a consistent interface.\n\n- ### FuzzyPartial\n\n  A variant of the `Partial\u003cT\u003e` inbuilt, and closely related to `StrictPartial`. `Partial` makes no guarantees about the members of the type `T`, as such they can be unions of `null`. This can introduce inconsistency for users of the type; expecting that members can be specified using either `null` or `undefined`, where only some can also use `null`. `FuzzyPartial` resolves this by specifying that all members of the type `T` can *ALSO* be `null`, ensuring a consistent interface.\n\n- ### TypeAssertion\n\n  A custom error with the name `TypeAssertion`. This type is exported as a value so that Errors of this type can be isolated from other errors using instance checks. It is possible to use the constructor to create and throw your own Errors if you wish, **but this may change in future**.\n\n## Changelog\n\n### 1.0.0\n\n- Initial release\n\n### 1.1.0\n\n- Documentation update.\n- Fix: asDefined was returning `unknown`.\n- Breaking change: rename ObjectDict to Dictionary.\n- Add: Nullish type ( `null | undefined` ).\n- Change: Dictionary no longer contains `T | undefined` union.\n- Change: Optional type now also includes `null` in the type union.\n\n### 1.1.1\n\n- Change: return type of `asOpt{TYPE}` is now `TYPE | undefined` instead of `Optional\u003cTYPE\u003e` ( removes null from union )\n- Documentation corrections.\n\n### 1.2.0\n\n- Add: Introduce `isStruct` and `asStruct` that allow the inspection of a object to see if it meets a specific interface.\n- Add: Optional variants of [Type Checks](#reference-type-checks) with form `isOpt{TYPE}`.\n- Breaking Change: `asDefined` can longer accept `null` as a fallback parameter.\n- Change: `asIndexable` now accepts arrays.\n- Add: `isIndexable` [type check](#reference-type-checks).\n- Change: Expose the `TypeAssert` type publicly.\n- Add: `InterfacePattern` type.\n- Change: modify the type names in errors to be closer to the TypeScript names.\n\n### 2.0.0\n\n- Add: `isUnion` and `isOptUnion` to allow checking if a value matches any type of a type union.\n- Add: `asUnion` and `asOptUnion` to allow casting a value to a type union.\n- Add: `isArrayOf` and `isOptArrayOf` to allow checking if a value is an array of a given type.\n- Add: `isDictionaryOf` and `isOptDictionaryOf` to allow checking if a value is a Dictionary of a given type.\n- Breaking Change: Recursive [Type Casts](#reference-type-casts) now take a [Type Check](#reference-type-checks) as an argument instead of a [Type Cast](#reference-type-casts), and no longer emit a copy of the input. As a side effect if you are upgrading from `asArrayRecursive(asOptString)` to `asArraryOf(isOptString)` or (similar) the output array may contain `null` as the elements are no longer transformed by an inner cast ( optional cast methods normalize output to `undefined` ).\n- Add: `isInstance` and `isOptInstance` to allow checking if a value is an instance of a given class.\n- Add: `asInstance` and `asOptInstance` to allow casting a value to an instance of a given class.\n- Breaking Change: `asRecord`, `asOptRecord`, `asRecordRecursive` and `asOptRecordRecursive` have been renamed to `asDictionary`, `asOptDictionary`, `asDictionaryOf` and `asOptDictionaryOf` respectively.\n- Breaking Change: `asArrayRecursive` and `asOptArrayRecursive` have been renamed to `asArrayOf` and `asOptArrayOf` respectively.\n- Breaking Change: rename `TypeAssert` to `TypeCheck`.\n\n### 2.1.0\n\n- Add: `makeStrictPartial` for converting `Partial\u003cT\u003e` to `StrictPartial`.\n- Add: types `StrictPartial` and `FuzzyPartial`, variants of the inbuilt `Partial` type.\n- Add: type `StrictRequired`, variant of `Required`.\n\n### 2.1.1\n\n- Fix: incorrect constraint on `makeStrictPartial` prevented passing in non-indexable instances.\n\n### 2.2.0\n\n- Add: `assertDefined` throws if the passed value is `Nullish`.\n- Add: `TypeAssertion` error class thrown by TypeAsserts.\n\n### 2.2.1\n\n- Fix: update sub-dependency to resolve [npm advisory 1654](https://www.npmjs.com/advisories/1654)\n\n### 2.2.2\n\n- Fix: `asInstance`, `asOptInstance`, `isInstance` and `isOptInstance` were not exported from the package.\n\n### 2.3.0\n\n- Change: build target to ES2018 instead of ES3.\n\n### 2.4.0\n\n- Add: `invariant` function to assist type assertion\n- Add: JSON assertion functions\n- Add: Basic type assertion functions\n- Add: Literal type casts and checks\n- Add: Primitive type, casts and checks\n- Documentation: Correct some typos in the `isStruct`/`asStruct` examples\n\n### 2.5.0\n\n- Add: `inspectType` function to describe the type of a value\n- Fix: `makeNumber` no longer returns a number strings prefixed with a number\n- Change: Type error messages now use the more descriptive `inspectType` instead of `typeof` for erroneous values\n\n### 2.6.0\n\n- Add: `asGuardedFunction` to wrap a function with parameter/return value type checks\n- Change: Depreciate the fallback parameter for all TypeCasts\n- Documentation: Simplify the contents into primary headings only\n- Change: Instead of being a custom subclass of Error TypeAssertion is now an alias to TypeError\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoporetech%2Fts-runtime-typecheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanoporetech%2Fts-runtime-typecheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanoporetech%2Fts-runtime-typecheck/lists"}