• Stars
    star
    282
  • Rank 146,549 (Top 3 %)
  • Language
    TypeScript
  • Created about 2 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A project to turn a file of JSON responses into TypeScript types

undefined

A project to turn a file of JSON responses into TypeScript types

Warning on code

I haven't really tried to organize this code. I made this code strictly as i learned more about the problem space. So the code looks like exploratory code, not production ready code.

To me, it seems like there is going to be a several pass compiler for this to be a real deal here.

I am unsure how much i want to pursue this beyond my needs

My needs have been met, i am unsure if I want to pursue this much further.

If anyone is interested in this, i can certainly help you get ramped up, whisper me twitter

Union Collapsing is really hard...

Its currently disabled because its creating incorrect types. But i think i am pretty dang close to it being correct.

Why create this?

I have a new database at Netflix with +100 unique events without definitions. I will define them...

Here is a reason for why you could use it:

  1. You have too many JSON objects to develop types for other than naming.
  2. You may have enums that need to get pulled out.
  3. You want as compact possible representation

How To Use

  1. Clone

    git clone [email protected]:ThePrimeagen/undefined.git
    
  2. Dependency installation

    yarn install
    
  3. Have a file filled with json responses (check out out)

  4. The data can be handed in a few ways

    cat <jsons_here> | npx ts-node src/undefined.ts stdin
    npx ts-node src/undefined.ts <json_here>
    
  5. You want to save this to a file?

    npx ts-node src/undefined.ts <json_here> > types.d.ts
    

Enums

You can specify what fields need to be lifted into enums. I make the assumption that enums are likely string values (though there is a case for me to fix this, PRs will be merged with little regard)

npx ts-node src/undefined.ts <json_here> --enums Foo,Bar > types.d.ts

This will take any top level fields on objects and attempt to pull out the values, convert it into an enum, put at top of definitions, and replace their type (usually string) as the enum.

There is an issue

Fix it and make a PR. The code is shitty because I rage wrote it all in ~1 hour on twitch.

ThePrimeagen

Support

Github sponsor or twitch prime babe!

More Repositories

1

harpoon

Lua
6,501
star
2

vim-be-good

vim-be-good is a nvim plugin designed to make you better at Vim Movements.
Lua
3,200
star
3

init.lua

Lua
3,166
star
4

.dotfiles

Perl
2,971
star
5

refactoring.nvim

The Refactoring library based off the Refactoring book by Martin Fowler
Lua
2,816
star
6

kata-machine

TypeScript
1,267
star
7

git-worktree.nvim

Lua
689
star
8

ts-rust-zig-deez

Java
605
star
9

htmx-lsp

its so over
Rust
602
star
10

anime

The repo that everyone deserves
546
star
11

tyrone-biggums

Clearly a repo about websockets and their comparison...
ReScript
462
star
12

vim-royale

Because Nano sucks
Rust
410
star
13

neovimrc

Lua
341
star
14

vim-apm

Vim APM, Actions per minute, is the greatest plugin since vim-slicedbread
Lua
324
star
15

fem-algos

FrontEnd Master algorithms!
JavaScript
271
star
16

CHADstack

Dockerfile
257
star
17

ansible

Dockerfile
244
star
18

vim-with-me

Go
242
star
19

keyboards

239
star
20

rust-for-typescript-devs

JavaScript
212
star
21

vim-fundamentals

JavaScript
184
star
22

ThePrimeagen

149
star
23

fem-htmx-proj

Go
139
star
24

primestack

Rust
135
star
25

dev

my next gen build for starting my system
Shell
121
star
26

vmrss

Shell
92
star
27

web3-smart-contracts

JavaScript
84
star
28

BunSpreader

We spread the buns
Zig
73
star
29

fem-algos-2

The Last Algorithm Class You Want
JavaScript
70
star
30

htmx_golang

Go
67
star
31

jvim.nvim

A simple json traverser for NeoVim
Lua
67
star
32

aoc

2020
Rust
65
star
33

fem-git

JavaScript
64
star
34

vimrc

64
star
35

yew-have-ligma

Elixir
62
star
36

orgwasm

CSS
61
star
37

2-simple-steps

Its literally that simple
TypeScript
59
star
38

js-perf-example

TypeScript
53
star
39

neural-js

A kick-ass neural network for javascript
JavaScript
47
star
40

vim-nav-playground

C
43
star
41

coin-toss-me-daddy

Rust
42
star
42

htmx-class-template

The starter template with server in go or rust
Rust
40
star
43

lsp-debug-tools.nvim

this probably isn't the droid you are looking for
OCaml
35
star
44

leftPadDeez

nuts
JavaScript
35
star
45

yt

All my yt videos that require to have some codes.
TypeScript
34
star
46

fem-htmx

JavaScript
33
star
47

game-of-life-vwm

Go
33
star
48

rusty-arduino

Rust
31
star
49

titty-sprinkles

Yes... This is the name for my NodeConfEU project
TypeScript
30
star
50

htmx-subscribe

HTML
30
star
51

test-these-besties

Go
30
star
52

htmx

Rust
28
star
53

jpegdegens

TypeScript
26
star
54

public-edging

Rust
26
star
55

beat-me-daddy

I put my sonic in my pi
Rust
26
star
56

ts-go-rust

JavaScript
26
star
57

go-vs-rust

The greatest cli comparison ever created
Elixir
26
star
58

uhh

When you keep forgetting those sweet sweet sweet sweet commands.
Go
25
star
59

best-of-stackoverflow

A DRAMATIC READING OF STACK OVERFLOW
24
star
60

objects-to-buffer

TypeScript
23
star
61

bun-vs-node

TypeScript
22
star
62

tmux-sessionizer

Shell
21
star
63

vim-arcade

21
star
64

fem-jsperf

JavaScript
20
star
65

rust-wasm-serverless

Rust
20
star
66

json-vs-proto

TypeScript
20
star
67

gspot

Rust
18
star
68

no-flap-november

the greatest
Go
18
star
69

ts-go-rust-projector

TypeScript
17
star
70

ocaml-aoc

OCaml
16
star
71

i-fixed

16
star
72

shooter-js

TypeScript
15
star
73

vim-deathmatch

Rust
15
star
74

milo

TypeScript
15
star
75

big-chungus

is amungus
TypeScript
14
star
76

real-prog-dvorak-zmk

Rust
14
star
77

zig-deez-structures

Zig
14
star
78

this-isnt-rust

There is no rust in this suppository
TypeScript
13
star
79

git-bisect

JavaScript
13
star
80

tree-navigation

Lua
12
star
81

more-htmx-eploration

Rust
12
star
82

javascwipt-performance

suck it piq
TypeScript
12
star
83

your-first-plugin

Example NeoVim Lua Plugin
Lua
11
star
84

projector

Project my config into your prebuild
Go
11
star
85

why-are-promises-slow

they are
11
star
86

cargo-chadr

Rust
11
star
87

chat-js

Rust
10
star
88

tier-list

HTML
10
star
89

he-uses-tabs

Rust
8
star
90

neovim-irc

C
8
star
91

jest-mem-test

JavaScript
8
star
92

the-great-sonnet-test

Go
7
star
93

rxjs-examples

JavaScript
7
star
94

ansible-dev-prod

Dockerfile
7
star
95

rfceez

Lua
7
star
96

todo

yes
C++
6
star
97

first-nvim-plugin

The template for writing your first nvim plugin
6
star
98

first-deno-project

JavaScript
6
star
99

fizzbuzz

A real programmers fizzbuzz
JavaScript
6
star
100

99-ocaml-problems

6
star