Settings

Theme

TypeScript compile-time dice rolls

github.com

3 points by Firfi · 3 comments

Reader

2 threads
rererereferred

Automating https://xkcd.com/221/ eh?

  • FirfiOP

    Well, in some sense, yes. There's a seed, of course! It's not always 4 unless it IS : )

FirfiOP

I needed to roll some "2d10 + 3"-like expressions in TypeScript, but found that there was no TypeScript dice library for some reason. There you go, then. Rolls both at compile time and at runtime.

TLDR

```ts const r = evaluate("d20", initializedState); // r knows it rolled "12" on type-level const v = valueOf(r); // value of v is 12, type is literal 12 ```

The code is controlled slop; tokens were burnt with mindfulness.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection