tessl install tessl/npm-io-ts@2.2.0TypeScript runtime type system for IO decoding/encoding
Agent Success
Agent success rate when using this tile
72%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.14x
Baseline
Agent success rate without this tile
63%
Build a runtime validator for product catalog data that can generate both a decoder for validation and a type guard for runtime checks from a single schema definition.
Create a reusable schema for products with the following structure:
From the single schema definition, generate:
The decoder should:
{id: 1, name: "Laptop", category: "electronics", price: 999.99, inStock: true}, the decoder returns success and the guard returns true @test{id: 2, name: "Book", category: "books", price: 19.99, inStock: true}, the decoder returns failure @test{id: 3, name: "Chair", category: "furniture", price: -50, inStock: false}, the decoder returns failure @test{id: 4, name: "Shirt", category: "clothing"}, the decoder returns failure @test@generates
import { Either } from 'fp-ts/Either';
/**
* Product type representing catalog items
*/
export interface Product {
id: number;
name: string;
category: 'electronics' | 'clothing' | 'furniture';
price: number;
inStock: boolean;
}
/**
* Decoder for validating product data
* Validates untrusted data against the product schema
*/
export const productDecoder: {
decode(input: unknown): Either<unknown, Product>;
};
/**
* Type guard for runtime product type checking
* Returns true if the input matches the product schema
*/
export const isProduct: (input: unknown) => input is Product;Provides schema-based type system with custom interpreters for generating decoders and guards from a single schema definition.
Provides functional programming utilities including Either type for representing validation results.