A type programming language which compiles to and interops with type-level TypeScript

Overview

Prakaar

Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a subset of TypeScript. See this twitter thread for an introduction.

You can install it via npm i -g prakaar. And use it via cli with cat foo.pr.ts | prakaar > foo.ts. Or programmatically with the prakaar/typescript-compiler module.

Currently, this is just a proof-of-concept and made for fun. But it probably could have a use-case as it does make type-level TypeScript way more accessible.

Feel free to open an issue for questions or feedback.

Basic example

// -------------------------
// ./foo.pr.ts

import { Type, O, U, B, T, p, t } from "prakaar/prelude"

export let omitFunctionKey = (t: Type) =>
  O.create(
    p(
      O.key(t),
      U.filter(k =>
        B.not(T.isSubtype(O.get(t, k), T.function))
      )
    ),
    k => O.get(t, k)
  )

let test = omitFunctionKey(t<{
  a: string,
  b: number,
  c: (_: { x: string }) => number,
  d: () => void
}>())


// -------------------------
// ./foo.ts (compiled)

import { T, U, O, B } from "prakaar/typescript-prelude"

export type omitFunctionKey<t> =
  { [_k in T.cast<(
      [O.key<t>] extends [infer _a0] ? 
      [(
        [_a0] extends [infer k] ?
        k extends unknown ?
        (B.not<T.isSubtype<O.get<t, k>, T.function_>>) extends true ?
        k : never : never : never
      )] extends [infer _a1] ? 
      _a1 : never : never
    ), keyof any>]:
      [_k] extends [infer k] ?
      O.get<t, k> : never
  }

type test =
  omitFunctionKey<{
    a: string,
    b: number,
    c: (_: { x: string }) => number,
    d: () => void
  }>

Interop example

// -------------------------
// ./exclude-hello.pr.ts

import { Type, U, B, p, t } from "../src/prelude"
import { IsHello } from "./external/is-hello"

export let ExcludeHello = (x: Type) =>
  p(x, U.filter(x =>
    B.not(t<IsHello<typeof x>>())
  ))


// -------------------------
// ./exclude-hello.ts (compiled)

import { T, U, O, B } from "../src/typescript-prelude"
import { IsHello } from "./external/is-hello"

export type ExcludeHello<x> =
  [x] extends [infer _a0] ? 
  [(
    [_a0] extends [infer x] ?
    x extends unknown ?
    ([x] extends [infer x] ?
    B.not<IsHello<x>> : never) extends true ?
    x : never : never : never
  )] extends [infer _a1] ? 
  _a1 : never : never


// -------------------------
// ./is-hello.ts

export type IsHello<T> =
  T extends "hello" ? true : false


// -------------------------
// ./test.ts

import { ExcludeHello } from "./exclude-hello.ts"

type Test =
  ExcludeHello<"hello" | "world" | "prakaar">

Future

  • Currently the code is really shabby because I just wanted to make a POC. I might rewrite it in PureScript (if I can make good bindings for babel).

  • The prelude currently only contains the functions used in the readme examples. After I rewrite this I'd gradually add and implement more prelude functions (and more features in general).

  • Optimizations. Eg, omitFunctionKey in above output can be optimized to something like this...

export type omitFunctionKey<t> =
  { [k in (
      keyof t extends infer p ?
      p extends unknown ?
        t[p & keyof t] extends ((...a: never[]) => unknown)
          ? never
          : p & keyof t
        : never : never
    )]:
      t[k]
  }
You might also like...

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

🐬 HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Dec 20, 2022

Jaksel Script, Programming language very modern and Indonesian style

Jaksel Script Jaksel Script is a new programming language, very modern, easy to learn, using Indonesia-slang language. No programming experience requi

Jan 3, 2023

The Javascript and canvas port of MarkovJunior : A Probabilistic Programming Language.

The Javascript and canvas port of MarkovJunior : A Probabilistic Programming Language.

MarkovJunior.js MarkovJunior is a probabilistic programming language where programs are combinations of rewrite rules and inference is performed via c

Nov 15, 2022

⚡ Extremely fast online playground for every programming language.

Riju Riju is a very fast online playground for every programming language. In less than a second, you can start playing with a Python interpreter or c

Dec 28, 2022

Programming language makes by hobby 3

Joule Programming language makes by hobby 3 About It's a compiled programming language written in JavaScript :/. Codes compile into Assembly code tha

Feb 17, 2022

VSCode extension for the rickroll-lang programming language (incomplete)

Rickroll-Lang VSCode Extension The Rick Roll programming language is a rickroll based, process oriented, dynamic, strong, esoteric programming languag

Oct 10, 2022

A Flow-based programming language for universal applications.

A Flow-based programming language for universal applications.

Hlang A Flow-based programming language for universal applications. Hlang aims to make programming easier, faster and more comfortable. It avoids codi

Dec 25, 2022

A programming language (WIP)

Umo programming language Concept Effect system (not implemented) Subtyping (not implemented) Opt-in shared mutability (not implemented) Gradual typing

Feb 25, 2022

One-stop Go+ programming language environment manager

One-stop Go+ programming language environment manager

InGop (Go+ language) One-stop Go+ programming language environment manager How do I learn the Go+ programming language quickly? Start with installatio

Nov 21, 2022
Comments
  • Not sure what the single letter variables in the prelude do

    Not sure what the single letter variables in the prelude do

    Hello, this library looks really interesting, and it’s a really cool approach to metaprogramming that I’ve wanted to try myself.

    Just a question, what do the single letter variables exported by the library do? I presume O stands for Object…? Why not make them full size variables?

    question 
    opened by tanishqkancharla 1
Owner
Devansh Jethmalani
Yeah sometimes I code
Devansh Jethmalani
Gleam is a beautiful little language that compiles to JS and to Erlang.

Gleam is a beautiful little language that compiles to JS and to Erlang. Esbuild is an excellent little js bundler. It's a great match! ??

Benjamin Wireman 5 Apr 5, 2022
Programing language that compiles to C.

Ekalang Ekalang is a simple programming language that can be interpreted during the development phase and then compiled into C. Its goal is to make sm

Ekazuki 4 Feb 23, 2022
Cookbook Method is the process of learning a programming language by building up a repository of small programs that implement specific programming concepts.

CookBook - Hacktoberfest Find the book you want to read next! PRESENTED BY What is CookBook? A cookbook in the programming context is collection of ti

GDSC-NITH 16 Nov 17, 2022
Write "hello world" in your native language, code "hello world" in your favorite programming language!

Hello World, All languages! ?? ?? Write "hello world" in your native language, code "hello world" in your favorite language! #hacktoberfest2022 How to

Carolina Calixto 6 Dec 13, 2022
The repository shows the compiler (simulator) of the Little Man Computer, which also contains some programs in the LMC programming language for implementing different functions.

Little Man Computer The repository shows the compiler (simulator) of the Little Man Computer, which also contains some programs in the LMC programming

Cow Cheng 2 Nov 17, 2022
A web component that allows you to run high level programming languages on your websites (static websites included!)

Code-Runner-Web-Component A web component that allows you to run high level programming languages on your website via the public Piston API Show your

Marketing Pipeline 28 Dec 16, 2022
A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framework.

Sveltosis Still in development A Svelte parser that compiles to Mitosis JSON, allowing you to write Svelte components once and compile to every framew

sveltosis 70 Nov 24, 2022
Plugin builder that compiles to several different discord client mods.

Builder Plugin builder that compiles to several different discord client mods. Supports Powercord Unbound Asstra BetterDiscord Installation git submod

Strencher 5 Dec 1, 2022
CancerDB: A public domain knowledge graph about cancer treatments that compiles to a CSV file.

CancerDB: A public domain csv file to help build the next great cure CancerDB is a public domain database and website containing facts about all types

Breck Yunits 21 Dec 15, 2022