Skip to content

risk/ts-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧩 TS Playground

TypeScript experiments and architecture sketches by risk.
Code featured in my Zenn articles.


💡 This repository contains small TypeScript experiments,
design pattern trials, and clean architecture prototypes, etc.

Each directory or file is mostly self-contained —
feel free to explore any of them.

Playground means: you can break it, fix it, or rebuild it — that's the point. 🎈


🚀 Getting Started

Setup

# Clone the repository
git clone https://github.com/risk/ts-playground.git
cd ts-playground

# Install dependencies
npm install

Run Examples

# Run any TypeScript file directly with tsx
npx tsx src/pipeline/pipeline.ts
npx tsx src/recursiveMonad/recursiveMonad.ts
npx tsx src/cleanArchitecture/cleanArchitecture.ts
npx tsx src/keyedPromiseAll/keyedPromiseAllv2.ts
npx tsx src/typeCalc/typeTest.ts
npx tsx src/mappedType/mappedType.ts
npx tsx src/distributiveConditionalType/distributiveConditionalType.ts
npx tsx src/caFramework/sandbox.ts
npx tsx src/gatePrototype/gatePrototype.ts
npx tsx src/gatePrototype/asyncGatePrototype.ts

# Or compile and run
npm run build
node dist/pipeline/pipeline.js

📚 Projects

These descriptions were written by Cursor AI. 🤖

Railway Oriented Programming with full type safety.

  • Error recovery mechanisms
  • Composable pipeline structure
  • Zero runtime overhead

Converting recursion into a chain structure to avoid stack overflow.

  • Bidirectional linked list
  • Generator-based lazy evaluation
  • Applicable to tree/graph traversal

Sample implementation of Clean Architecture pattern.

  • Layer separation (Entity, UseCase, Gateway, Presenter)
  • Dependency injection
  • Result type pattern

Four arithmetic operations implemented at the type level.

  • Addition, subtraction, multiplication, division
  • Numbers represented as array lengths
  • Pure type-level computation with zero runtime cost

Educational examples for understanding TypeScript's type system.

  • extends and infer keyword usage
  • Deconstructing function types with Parameters and ReturnType
  • Array pattern matching with conditional types

Learn Mapped Types through a fun fruit-themed tutorial.

  • Step-by-step explanation from Record to Mapped Types
  • Understanding as const and type widening
  • Transforming types (arrays, functions with arguments)
  • Practical pattern: function table with type constraints

Deep dive into how TypeScript distributes union types in conditional types.

  • How T extends U distributes over unions
  • Preventing distribution with [T] wrapper
  • Implementing Extract and Exclude from scratch
  • Boolean literal expansion behavior

Type-level enforcement of Clean Architecture dependency rules.

  • Layer dependency validation at compile-time
  • InterfacePolicy for declaring allowed consumers
  • LayerPolicy for bidirectional dependency checking
  • Architectural constraints as TypeScript types

Keyed Promise.all v1 - Failed Attempt

Enhanced Promise.all that returns results by meaningful keys instead of array indices.

  • Type inference issues: Function types get reduced to constraints
  • Kept as a learning example of TypeScript's limitations

Improved version with perfect type inference using class-based wrapping.

  • Builder pattern for fluent API design
  • Perfect type inference through KeyedFunc wrapper class
  • Result type pattern for type-safe error handling
  • handleResult helper for convenient result processing

Type-safe data validation and transformation using Zod schemas.

  • Input/Output validation with strict schema enforcement
  • Curried function design for reusable gate handlers
  • Synchronous and asynchronous versions
  • Complete type safety with external data isolation
  • Unified error handling with custom GateError types

🪶 License

Licensed under the MIT License.
Free to learn, remix, and build upon.

About

Typescriptのお勉強や作ったコードをあげておくところ。

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors