1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
---
id: examples
title: Examples
---
#### Validate that an unknown value is a port protocol:
```ts
const isPort = t.applyCascade(t.isNumber(), [
t.isInteger(),
t.isInInclusiveRange(1, 65535),
]);
isPort(42000);
```
#### Validate that an unknown value is a record with specific fields, regardless of the others:
```ts
const isDiv = t.isObject({
tagName: t.isLiteral(`DIV`),
}, {
extra: t.isUnknown(),
});
isDiv({tagName: `div`, appendChild: () => {}});
```
#### Validate that a specific field is a specific value, and that others are all numbers:
```ts
const isModel = t.isObject({
uid: t.isString(),
}, {
extra: t.isDict(t.isNumber()),
});
isModel({uid: `foo`, valA: 12, valB: 24});
```
|