> For the complete documentation index, see [llms.txt](https://radoslaw-medryk.gitbook.io/verifica/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://radoslaw-medryk.gitbook.io/verifica/getting-started/typescript.md).

# Typescript

Verifica comes with type definitions, so no additional packages are needed.

## ensure()

```typescript
function ensure(verificable: Verificable, predicate: Predicate<TOut>): TOut
```

Function `ensure` returns the checked value if the `predicate` matches. The type of returned value is the same as the generic parameter type of the `Predicate<TOut>` . This allows to use the value with the correct type after ensuring it matches the `predicate`:

```typescript
import { asVerificable, ensure, isNumber } from "verifica";

function add(a: unknown, b: unknown): number {
    const vparams = asVerificable({ a, b });
    
    // both `aNum` and `bNum` will be of type `string`:
    const aNum = ensure(vparams.a, isNumber);
    const bNum = ensure(vparams.b, isNumber);
    
    return aNum + bNum;
}
```
