Skip to content

Commit

Permalink
Add readme example for schema with type argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Rawlinson authored and Hugh Rawlinson committed Jun 8, 2022
1 parent 1d89e04 commit 0ac410d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,27 @@ if (isSuccess(message)) {
}
```

schema supports a type argument for associating a schema with an existing type

```ts
interface TestInterface {
id: number;
name: string;
}

const isTestInterface = schema<TestInterface>({
id: isNumber,
name: isString
});

if (isTestInterface(message)) {
// let message: TestInterface
message;
}
```

````
### `every()
Runtime array type validation. Checks each element of an array.
Expand All @@ -243,7 +264,7 @@ let arr: unknown[] = [1, 2, 3];
if (every(isNumber)(arr)) {
let typeCheck: number[] = arr;
}
```
````

Works with any narrowing validator, including schemas.

Expand Down

0 comments on commit 0ac410d

Please # to comment.