Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aliberro39109/typo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typo-logo

🧠 Typo – A TypeScript Type-Level Programming Language

Typo is a programming language built purely on TypeScript's type system — no functions, no runtime, no actual execution in the traditional sense. Just... types.


✨ What is Typo?

Typo is an experimental project that explores the idea of treating TypeScript types as the building blocks for a programming language. This includes:

  • Arithmetic operations (Add, Sub, Mul, Div, Mod)
  • Comparison operations (Equal, NotEqual, GreaterThan, LessThan)
  • Branching logic (IfElse)
  • Booleans & Logic operators (And, Or, Negate)
  • Negative & positive number support
  • Variables via type inference
  • Simulated output with Print
  • Basic "computation block" with scoping using function arguments

All of this is accomplished using TypeScript's advanced type capabilities like conditional types, recursive types, literal type inference, and template literal types. Some stuff may require some additional time for processing, as this heavily rely on recursion.

Note: This is not meant for production use — it's a fun, brain-twisting exploration of what's possible with types only. I know you will not take it to production, but it will not hurt to mention that :)

Try it out here on Typescript Playground


🚀 Motivation

While helping a friend reinstall Windows, I opened the TypeScript Playground to pass the time. A couple of random lines of code later, an idea sparked — what if I could create a full language just using types?

Two hours later, Typo was born.

--

🛠 How to Use It

git clone https://github.com/aliberro39109/typo.git
cd typo
  1. Clone the repo as instructed above.
  2. Create a new file in your favorite editor and include typo.ts.
  3. Define a "program" as a type, then evaluate it using Compute<...>. Evaluation is done by hovering your mouse over it, check the attached examples in the /examples.

🔍 How Does It Work?

You define your program inside a function-like type. Each line can define a variable, perform a computation, or simulate a Print. Since Typescript types can be numbers, strings, and can be more specificially a value/collection of values out of these (1, 2, "Hello", or collection 1 | 2), this part is taken care of. Addition is done by converting the numbers into an array containing nothing, then concatenating both arrays, and lastly finding the length. Subtraction is the way around with some tricky caveats. Now the Print uses some special markers so we can denote what computed values we need to print, then we join them with \n.

import type { Add, Mul, Print, MakeNegative, Compute } from "./typo.ts";
type Code = (
	X: 10,
	Y: 20,
	Z: Add<typeof X, typeof Y>,
	T: Mul<typeof Y, MakeNegative<typeof Z>>,
	Px: Print<typeof X>,
	Py: Print<typeof Y>,
	Pz: Print<typeof Z>,
	Pt: Print<typeof T>
) => never;

type Result = Compute<Code>; //"10\n20\n30\n-600\n"

🤝 Feedback & Contributions

I'd love to hear your ideas! Open an issue or PR, whether it's a bug, an enhancement, or a fun demo.


📝 License

MIT


About

A toy programming language built entirely using TypeScript's type system!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •