NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
TypeScript compile-time dice rolls (github.com)
rererereferred 2 days ago [-]
Automating https://xkcd.com/221/ eh?
Firfi 2 days ago [-]
Well, in some sense, yes. There's a seed, of course! It's not always 4 unless it IS : )
Firfi 2 days ago [-]
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.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 05:00:56 GMT+0000 (Coordinated Universal Time) with Vercel.