1.6.1 • Published 4 years ago

@ulangi/assert v1.6.1

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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:

MethodExplanation
assertExistsAssert that variable should not be neither null nor undefined.
assertTypeAssert the type of variable using a typeguard function.
assertRequiredAssert variable to follow a certain Joi schema whose properties are required unless stated otherwise.
assertOptionalAssert variable to follow a certain Joi schema whose properties are optional unless stated otherwise.
1.6.1

4 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago