This is annoying as either a verboseif-clause is needed to inform the TypeScript compiler that
iAmDefined is not undefined, or an unsafe type assertion! is needed. Similar problems exist
for null.
This module solves this family of problems with expectToBeDefined.Simply replace
expect(iAmDefined).toBeDefined() with expectToBeDefined(iAmDefined), and the above error is
gone.
Utilities that wrap some assertions in vitest!expect with type assertions.
One nuance with some of the vitest!expect functions are the lack of type assertions.
Example
This is annoying as either a verbose
if
-clause is needed to inform the TypeScript compiler thatiAmDefined
is not undefined, or an unsafe type assertion!
is needed. Similar problems exist fornull
.This module solves this family of problems with expectToBeDefined.Simply replace
expect(iAmDefined).toBeDefined()
withexpectToBeDefined(iAmDefined)
, and the above error is gone.