CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ts-toolbelt

TypeScript's largest utility library providing 200+ type utilities for advanced type manipulation.

Pending
Overview
Eval results
Files

community.mddocs/

Community Module

Community-contributed utilities providing specialized type checking and deep operations.

Capabilities

Deep Inclusion Checking

Check for deep inclusion within complex nested structures.

/**
 * Check if a type includes another type deeply within nested structures
 * @param T - Type to search within
 * @param U - Type to search for
 * @returns 1 if U is found deeply within T, 0 otherwise
 */
type IncludesDeep<T, U> = IncludesDeepImpl<T, U>;

Usage Examples:

import { Community } from "ts-toolbelt";

// Deep nested structure
type NestedObject = {
  user: {
    profile: {
      settings: {
        theme: "dark" | "light";
        notifications: boolean;
      };
    };
  };
};

// Check if "dark" is included deeply
type HasDarkTheme = Community.IncludesDeep<NestedObject, "dark">; // 1

// Check for non-existent type
type HasInvalidType = Community.IncludesDeep<NestedObject, "invalid">; // 0

// Array deep inclusion
type NestedArray = [1, [2, [3, ["hello", "world"]]]];
type HasString = Community.IncludesDeep<NestedArray, string>; // 1
type HasSymbol = Community.IncludesDeep<NestedArray, symbol>; // 0

Literal Type Checking

Determine if a type is a literal type (specific value) rather than a general type.

/**
 * Check if a type is a literal type
 * @param T - Type to check for literal status
 * @returns 1 if T is a literal type, 0 otherwise
 */
type IsLiteral<T> = IsLiteralImpl<T>;

Usage Examples:

import { Community } from "ts-toolbelt";

// Literal types
type IsStringLiteral = Community.IsLiteral<"hello">; // 1
type IsNumberLiteral = Community.IsLiteral<42>; // 1
type IsBooleanLiteral = Community.IsLiteral<true>; // 1

// General types
type IsStringGeneral = Community.IsLiteral<string>; // 0
type IsNumberGeneral = Community.IsLiteral<number>; // 0
type IsBooleanGeneral = Community.IsLiteral<boolean>; // 0

// Union literals vs general unions
type UnionLiteral = Community.IsLiteral<"red" | "green" | "blue">; // Implementation dependent
type UnionGeneral = Community.IsLiteral<string | number>; // 0

// Object and array literals
type ObjectLiteral = Community.IsLiteral<{ name: "John"; age: 30 }>; // 1
type TupleLiteral = Community.IsLiteral<[1, 2, 3]>; // 1

// Template literals
type TemplateLiteral = Community.IsLiteral<`Hello ${string}`>; // Implementation dependent

Practical Applications

Real-world usage patterns for community utilities.

Usage Examples:

import { Community, A } from "ts-toolbelt";

// Configuration validation
type Config = {
  environment: "development" | "staging" | "production";
  features: {
    auth: {
      provider: "oauth" | "saml";
      settings: {
        timeout: number;
        retries: 3 | 5 | 10;
      };
    };
  };
};

// Check if specific values are supported
type SupportsOAuth = Community.IncludesDeep<Config, "oauth">; // 1
type SupportsLDAP = Community.IncludesDeep<Config, "ldap">; // 0
type HasRetryLimit = Community.IncludesDeep<Config, 3>; // 1

// Type constraint validation
type ValidateConfigValue<T> = Community.IsLiteral<T> extends 1
  ? "literal_value"
  : "general_type";

type EnvValidation = ValidateConfigValue<"production">; // "literal_value"
type TimeoutValidation = ValidateConfigValue<number>; // "general_type"

// API response validation
type ApiResponse = {
  status: 200 | 404 | 500;
  data: {
    users: Array<{
      id: string;
      role: "admin" | "user" | "guest";
    }>;
  };
};

type HasAdminRole = Community.IncludesDeep<ApiResponse, "admin">; // 1
type HasModeratorRole = Community.IncludesDeep<ApiResponse, "moderator">; // 0
type HasSuccessStatus = Community.IncludesDeep<ApiResponse, 200>; // 1

// Form validation
type FormField<T> = {
  value: T;
  isLiteral: Community.IsLiteral<T>;
  hasSpecificValue: <V>(value: V) => Community.IncludesDeep<T, V>;
};

type EmailField = FormField<string>; // isLiteral: 0
type StatusField = FormField<"pending" | "approved" | "rejected">; // isLiteral: implementation dependent

// Conditional type construction
type ConditionalType<T> = Community.IsLiteral<T> extends 1
  ? { literalValue: T; type: "specific" }
  : { type: "general"; acceptedValues: T };

type StringType = ConditionalType<string>; // { type: "general"; acceptedValues: string }
type HelloType = ConditionalType<"hello">; // { literalValue: "hello"; type: "specific" }

Types

// Community module provides specialized utilities
// Implementation details are internal to the module

Install with Tessl CLI

npx tessl i tessl/npm-ts-toolbelt

docs

any.md

boolean.md

class.md

community.md

function.md

index.md

iteration.md

list.md

misc.md

number.md

object.md

string.md

testing.md

union.md

tile.json