@ulangi/assert
TypeScript icon, indicating that this package has built-in type declarations

1.6.1 • Public • Published

assert

This library is used with TypeScript support in production code where you want to reduce/infer type of certain variables.

Here is one good example:

type User = { userId: string }

// Assume that we have getUser() that returns either null or an User object
funtion getUser(): null | User {
}

// When we know that getUser() will certainly not return null beyond this point,
// use assertExists to reduce the type to User.
const { userId } = assertExists(getUser())

API:

Method Explanation
assertExists Assert that variable should not be neither null nor undefined.
assertType Assert the type of variable using a typeguard function.
assertRequired Assert variable to follow a certain Joi schema whose properties are required unless stated otherwise.
assertOptional Assert variable to follow a certain Joi schema whose properties are optional unless stated otherwise.

Readme

Keywords

none

Package Sidebar

Install

npm i @ulangi/assert

Weekly Downloads

1

Version

1.6.1

License

MIT

Unpacked Size

17.9 kB

Total Files

39

Last publish

Collaborators

  • jimmyloi