CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-io-ts

tessl install tessl/npm-io-ts@2.2.0

TypeScript 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%

task.mdevals/scenario-10/

User Configuration Validator

Build a user configuration validator that validates and parses configuration objects from external sources using runtime type checking.

Requirements

Your system should validate user configuration objects that contain user profiles. The configuration must include:

  • A username field (string, required)
  • An age field (number, required)
  • An email field (string, required)
  • An isActive field (boolean, required)

Your implementation should:

  1. Define a validation schema for the user configuration structure
  2. Implement a validateConfig function that accepts an unknown input and returns a validation result
  3. When validation succeeds, return an object with success: true and the validated data
  4. When validation fails, return an object with success: false and a user-friendly errors array containing error messages

Test Cases

  • When given a valid configuration object { username: 'alice', age: 30, email: 'alice@example.com', isActive: true }, it returns success with the validated data @test
  • When given an invalid configuration with a string age { username: 'bob', age: '25', email: 'bob@example.com', isActive: true }, it returns failure with error messages @test
  • When given a configuration missing the email field { username: 'charlie', age: 35, isActive: false }, it returns failure with error messages @test

Implementation

@generates

API

export interface ValidationSuccess<T> {
  success: true;
  data: T;
}

export interface ValidationFailure {
  success: false;
  errors: string[];
}

export type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;

export function validateConfig(input: unknown): ValidationResult<{
  username: string;
  age: number;
  email: string;
  isActive: boolean;
}>;

Dependencies { .dependencies }

io-ts { .dependency }

Provides runtime type validation and decoding capabilities.

fp-ts { .dependency }

Provides functional programming utilities including the Either type used by io-ts.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/io-ts@2.2.x
tile.json