or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

checker-creation.mddata-validation.mderror-handling.mdindex.mdinterface-method-validation.mdtype-definition-system.md

checker-creation.mddocs/

0

# Checker Creation and Management

1

2

Create checker instances from type suites generated by ts-interface-builder, enabling runtime validation of TypeScript interfaces.

3

4

## Capabilities

5

6

### createCheckers Function

7

8

Creates checker instances from one or more type suites. Combines multiple type suites to resolve cross-references between types.

9

10

```typescript { .api }

11

/**

12

* Takes one or more type suites and combines them into a suite of interface checkers.

13

* @param typeSuite - One or more type suites (generated by ts-interface-builder)

14

* @returns Object mapping type names to Checker objects

15

*/

16

function createCheckers(...typeSuite: ITypeSuite[]): ICheckerSuite;

17

```

18

19

**Usage Examples:**

20

21

```typescript

22

import { createCheckers } from "ts-interface-checker";

23

import userTypes from "./user-ti";

24

import addressTypes from "./address-ti";

25

26

// Single type suite

27

const { User } = createCheckers(userTypes);

28

29

// Multiple type suites for cross-references

30

const { User, Address } = createCheckers(userTypes, addressTypes);

31

32

// Access checkers by name

33

User.check({ name: "Alice", age: 30 });

34

Address.check({ street: "123 Main St", city: "Anytown" });

35

```

36

37

### ICheckerSuite Interface

38

39

Maps type names to their corresponding Checker instances.

40

41

```typescript { .api }

42

/**

43

* Suite of checker instances mapped by type name

44

*/

45

interface ICheckerSuite {

46

[name: string]: Checker;

47

}

48

```

49

50

### ITypeSuite Interface

51

52

Maps type names to their TType definitions. Used as input to createCheckers.

53

54

```typescript { .api }

55

/**

56

* Suite of type definitions mapped by type name

57

*/

58

interface ITypeSuite {

59

[name: string]: TType;

60

}

61

```

62

63

### Type Suite Combination

64

65

When multiple type suites are provided, they are combined to resolve type references across modules.

66

67

**Usage Examples:**

68

69

```typescript

70

// shapes-ti.ts (generated)

71

export const Rectangle = t.iface([], {

72

width: "number",

73

height: "number",

74

color: "Color" // References Color from color-ti

75

});

76

77

// color-ti.ts (generated)

78

export const Color = t.union("string", "RGB");

79

export const RGB = t.tuple("number", "number", "number");

80

81

// Usage

82

import shapeTypes from "./shapes-ti";

83

import colorTypes from "./color-ti";

84

85

const { Rectangle } = createCheckers(shapeTypes, colorTypes);

86

Rectangle.check({

87

width: 100,

88

height: 50,

89

color: [255, 0, 0] // RGB tuple

90

});

91

```

92

93

### Checker Instance Properties

94

95

Each Checker instance contains validation methods and utility functions for the specific type.

96

97

```typescript { .api }

98

/**

99

* Main validation class for checking data against types

100

*/

101

class Checker {

102

constructor(private suite: ITypeSuite, private ttype: TType, private _path: string = 'value');

103

}

104

```