CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ts-interface-checker

Runtime library to validate data against TypeScript interfaces

Pending
Overview
Eval results
Files

checker-creation.mddocs/

Checker Creation and Management

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

Capabilities

createCheckers Function

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

/**
 * Takes one or more type suites and combines them into a suite of interface checkers.
 * @param typeSuite - One or more type suites (generated by ts-interface-builder)
 * @returns Object mapping type names to Checker objects
 */
function createCheckers(...typeSuite: ITypeSuite[]): ICheckerSuite;

Usage Examples:

import { createCheckers } from "ts-interface-checker";
import userTypes from "./user-ti";
import addressTypes from "./address-ti";

// Single type suite
const { User } = createCheckers(userTypes);

// Multiple type suites for cross-references
const { User, Address } = createCheckers(userTypes, addressTypes);

// Access checkers by name
User.check({ name: "Alice", age: 30 });
Address.check({ street: "123 Main St", city: "Anytown" });

ICheckerSuite Interface

Maps type names to their corresponding Checker instances.

/**
 * Suite of checker instances mapped by type name
 */
interface ICheckerSuite {
  [name: string]: Checker;
}

ITypeSuite Interface

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

/**
 * Suite of type definitions mapped by type name
 */
interface ITypeSuite {
  [name: string]: TType;
}

Type Suite Combination

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

Usage Examples:

// shapes-ti.ts (generated)
export const Rectangle = t.iface([], {
  width: "number",
  height: "number",
  color: "Color" // References Color from color-ti
});

// color-ti.ts (generated)  
export const Color = t.union("string", "RGB");
export const RGB = t.tuple("number", "number", "number");

// Usage
import shapeTypes from "./shapes-ti";
import colorTypes from "./color-ti";

const { Rectangle } = createCheckers(shapeTypes, colorTypes);
Rectangle.check({
  width: 100,
  height: 50,
  color: [255, 0, 0] // RGB tuple
});

Checker Instance Properties

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

/**
 * Main validation class for checking data against types
 */
class Checker {
  constructor(private suite: ITypeSuite, private ttype: TType, private _path: string = 'value');
}

Install with Tessl CLI

npx tessl i tessl/npm-ts-interface-checker

docs

checker-creation.md

data-validation.md

error-handling.md

index.md

interface-method-validation.md

type-definition-system.md

tile.json