TypeScript Type-Level Logic Utilities

0.0.0 · abandoned · verified Sun Apr 19

This package provides experimental type-level boolean logic primitives using TypeScript's advanced generic system. With a version of `0.0.0` and last published over seven years ago (September 2018), it is in an extremely early, experimental state and is effectively abandoned. There is no established release cadence, and it completely lacks documentation, including a README. Its intended purpose is for advanced TypeScript developers requiring compile-time type validation or metaprogramming, allowing for boolean operations such as AND, OR, and NOT to be performed directly within the type system. This enables the creation of more robust and self-documenting types for intricate conditional logic scenarios, distinguishing itself by offering these utilities as pure type definitions rather than runtime values.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic type-level boolean logic operations (AND, OR, NOT) using generic types.

import type { True, False, And, Or, Not } from 'typescript-logic';

// Define some type-level boolean variables
type IsLoggedIn = True;
type HasAdminPermissions = False;
type IsPremiumUser = True;

// Demonstrate type-level AND logic
type CanAccessAdminPanel = And<IsLoggedIn, HasAdminPermissions>;
// Expected: False

// Demonstrate type-level OR logic
type CanViewPremiumContent = Or<IsPremiumUser, HasAdminPermissions>;
// Expected: True

// Demonstrate type-level NOT logic
type IsGuest = Not<IsLoggedIn>;
// Expected: False

// Combine operations
type CanPerformCriticalAction = And<IsLoggedIn, Or<HasAdminPermissions, IsPremiumUser>>;
// Expected: And<True, Or<False, True>> -> And<True, True> -> True

// Verify the results (compile-time assertion)
type Test1 = CanAccessAdminPanel extends False ? true : false;
const test1Result: Test1 = true;

type Test2 = CanViewPremiumContent extends True ? true : false;
const test2Result: Test2 = true;

type Test3 = IsGuest extends False ? true : false;
const test3Result: Test3 = true;

type Test4 = CanPerformCriticalAction extends True ? true : false;
const test4Result: Test4 = true;

view raw JSON →