TypeScript runtime type system for IO decoding/encoding
72
Build a runtime validation system for a complex user profile data structure that includes nested objects and collections.
The system must validate user profile data that contains multiple levels of nested objects and arrays. A valid user profile has the following structure:
@generates
/**
* Validates user profile data against the expected schema.
* Returns a validation result that indicates success or failure with error details.
*/
export function validateUserProfile(data: unknown): ValidationResult;
/**
* Type representing the validated user profile structure.
*/
export type UserProfile = {
user: {
id: number;
username: string;
email: string;
};
settings: {
preferences: {
theme: "light" | "dark";
language: string;
notifications: boolean;
};
privacy: {
profileVisible: boolean;
allowMessages: boolean;
};
};
addresses: Array<{
street: string;
city: string;
zipCode: string;
coordinates: {
latitude: number;
longitude: number;
};
}>;
socialConnections: Array<{
platform: "twitter" | "linkedin" | "github";
profile: {
handle: string;
verified: boolean;
};
}>;
};
/**
* Validation result containing either the validated data or error information.
*/
export type ValidationResult =
| { success: true; data: UserProfile }
| { success: false; errors: string[] };Provides runtime type validation for TypeScript.
Provides functional programming utilities for handling validation results.
Install with Tessl CLI
npx tessl i tessl/npm-io-tsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10