TypeScript's type system is Turing-complete, but complex type transformations often result in unreadable "type gymnastics". This library applies Flow-Based Programming (FBP) principles to the type level, making type transformations:
- Composable: Chain type transformations like data flows
- Port-First: Multi-port nodes for complex data routing
- DAG-Capable: Express computation graphs impossible in linear pipes
- Declarative: Define typeflows visually with structured topology
| Feature | HotScript | tlang | Advantage |
|---|---|---|---|
| Architecture | Single-param Pipe | Multi-port Node + DAG | โ Superior |
| Branching | โ Not supported | โ Supported | ๐ Unique |
| Merging | โ Not supported | โ Supported | ๐ Unique |
| Multi-input nodes | Requires Apply/Call | Native support | ๐ Unique |
| Tuples | 13 operations | 16 operations | โ Caught up |
| Strings | 18 operations | 22 operations | โ Caught up |
| Objects | Basic + Advanced | Basic + Advanced | โ Caught up |
| Numbers | BigInt arithmetic | Tuple-based | โ Caught up |
| Booleans | 4 operations | 5 operations | โ Caught up |
| Unions | Map, Extract, Exclude | Map, Extract, Exclude | โ Caught up |
tlang = HotScript's features + FBP's powerful architecture ๐ช
import type { Pipe, Omit, Pick } from '@atools/tlang'
type User = {
id: number
email: string
password: string
secret: string
}
// Simple linear transformation
type PublicUser = Pipe<User, [
Omit<'password' | 'secret'>,
Pick<'id' | 'email'>
]>
// Result: { id: number; email: string }import type { Exec, Out, TypeFlow } from '@atools/tlang'
// Branching: One input, multiple outputs
type Split = Exec<SplitNode, { value: 3 }>
// { original: 3, doubled: 6 }
type BranchA = Exec<DoubleNode, { in: Out<Split, 'original'> }>
type BranchB = Exec<IncrementNode, { in: Out<Split, 'doubled'> }>
// Merging: Multiple inputs, one output
type Merged = Exec<AddNode, {
a: Out<BranchA, 'out'>, // From branch 1
b: Out<BranchB, 'out'> // From branch 2
}>
// { sum: 12 }
// Declarative TypeFlow Definition
type MyTypeFlow = TypeFlow<
{
split: SplitNode
doubleNode: DoubleNode
incNode: IncrementNode
addNode: AddNode
},
[
{ from: { node: 'split'; port: 'original' }; to: { node: 'doubleNode'; port: 'in' } },
{ from: { node: 'split'; port: 'doubled' }; to: { node: 'incNode'; port: 'in' } },
{ from: { node: 'doubleNode'; port: 'out' }; to: { node: 'addNode'; port: 'a' } },
{ from: { node: 'incNode'; port: 'out' }; to: { node: 'addNode'; port: 'b' } }
],
{ split: { value: 3 } }
>HotScript's Pipe fundamentally cannot express these DAG structures!
npm install @atools/tlang
# or
pnpm add @atools/tlangThe fundamental unit - all nodes have inputs and outputs:
interface MyNode extends Node {
inputs: { a: number; b: number }
outputs: { sum: number }
}Execute a node with inputs, get all outputs:
type Result = Exec<AddNode, { a: 2, b: 3 }>
// { sum: 5 }Extract value from a specific output port:
type Sum = Out<Result, 'sum'>
// 5Linear pipeline for single-port nodes { in } โ { out }:
type Result = Pipe<5, [DoubleNode, IncrementNode]>
// 11Declarative DAG definition:
type MyTypeFlow = TypeFlow<
{ node1: Node1, node2: Node2 },
[{ from: {...}, to: {...} }],
{ initialData }
>Map, Filter, Reduce, Join, Head, Tail, Last, At, Reverse, Concat, ToUnion, ToIntersection, Length, IsEmpty, Prepend, Append
Split, Replace, Repeat, CamelCase, SnakeCase, KebabCase, Uppercase, Lowercase, Capitalize, Uncapitalize, Trim, TrimLeft, TrimRight, StartsWith, EndsWith, Includes, Length, ToTuple, ToString, ToNumber, Prepend, Append
Namespace operations (6): MapValues, MapKeys, Keys, Values, Entries, FromEntries
Top-level basic operations (6): Omit, Pick, Partial, Required, Readonly, Extend
Add, Sub, Mul, Div, Mod, Abs, Negate, Max, Min, Compare, Equal, LessThan, GreaterThan
And, Or, Not, Equals, Xor
Map, Extract, Exclude, UnionKeys, UnionToIntersection
// Transform backend data through validation and formatting
type UserProcessing = TypeFlow<
{
split: UserSplitNode,
validateEmail: ValidateEmailNode,
hashPassword: HashPasswordNode,
merge: MergeUserNode
},
[
{ from: { node: 'split'; port: 'emailData' }; to: { node: 'validateEmail'; port: 'in' } },
{ from: { node: 'split'; port: 'passwordData' }; to: { node: 'hashPassword'; port: 'in' } },
{ from: { node: 'validateEmail'; port: 'out' }; to: { node: 'merge'; port: 'email' } },
{ from: { node: 'hashPassword'; port: 'out' }; to: { node: 'merge'; port: 'password' } }
],
{ initialUser }
>// One input branches to multiple validators, then merges results
type FormValidation = TypeFlow<
{ split: SplitInput, emailCheck: Email, phoneCheck: Phone, merge: CombineResults },
[/* connections */],
{ formData }
>tlang comes with a full-featured visual editor that brings type-level programming to life! Build complex type transformations by dragging and dropping nodes, connecting them visually, and seeing the generated TypeScript code in real-time.
- ๐ฏ Drag & Drop Interface - Intuitive visual node editor powered by ReactFlow
- ๐ Live Connections - Connect node ports to build complex type transformation graphs
- ๐ป Code Generation - Automatic TypeScript code generation from your visual graph
- โก Real-time Execution - TypeScript type checker runs in-browser using official @typescript/vfs
- ๐ DAG Support - Build branching and merging flows impossible in linear pipelines
- ๐จ Syntax Highlighting - Beautiful code display with Prism.js
- โ Validation - Real-time graph validation with helpful error messages
- ๐ฆ Examples - Pre-built examples to get you started quickly
cd playground
pnpm install
pnpm run devOpen your browser and start building type-level computation graphs visually!
- ๐ Type Debugger - Step through type evaluation process
- ๐พ Save/Load Projects - Persist your type graphs locally or in the cloud
- ๐ Interactive Tutorials - Learn type-level programming through guided exercises
- ๐ Share & Collaborate - Share your type graphs with others via URL
- Lines of Code: ~3700+ type definitions
- Test Coverage: 89 tests, 100% passing
- Feature Parity: 100% of HotScript core features
- Unique Features: DAG support (HotScript 0%)
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
Tlang: Type-level programming, evolved. ๐



