The Lab · interactive explainer
Your authorization check is a line of code sitting next to the dangerous call — and nothing connects them. One missed await, one stale rule, and the hole is silent. This is an interactive tour of gdp-ts, the tiny TypeScript library that makes the dangerous function demand proof — a compile-time token only a trusted checker can mint. No proof, no compile.
Stop checking authorization near the call. Make the call impossible without the check. Proofs are ghosts: they do everything at compile time and nothing at runtime — about 0.3 ms of typechecking per call site, zero extra queries, zero dependencies.
Walk through the exact failure, one tap at a time. This is the code the library's README opens with — an Express-style handler, paraphrased.
The fix isn't a bigger check. It's a connection the compiler can see.
Give the runtime value a compile-time-only name. Two project IDs that are both string at runtime become distinguishable to the compiler — it can now tell which project you mean, not just what kind of value it is.
name(viewer.id, ProjectId(req.params.id), async (user, project) => { // inside here, `user` and `project` carry unique compile-time names. // project-A and project-B are no longer interchangeable. });
One trusted module does the check and mints the proof — or returns null. Nobody else can mint one. At runtime a proof is a frozen { kind } object: a ghost.
// proofs/user-is-project-admin.ts — the ONLY place that can mint this proof export async function userIsProjectAdmin(user, project) { const role = await db.roleInProjectTeam(user.value, project.value); return (role === "owner" || role === "member") ? UserIsProjectAdmin.prove(user, project) : null; }
The sensitive function takes the proof as a parameter. Call it with the wrong proof, a proof about a different project, or no proof at all — compile error. The data layer never performs the check; it just demands the receipt.
export function disablePasswordProtection( project, // Named<P, ProjectId> _proof: UserIsProjectAdmin<U, P> // proof about THIS user, THIS project ) { ... }
Pick a way to call the sensitive function. The simulated compiler rules on each one — this is the whole idea, compressed into a button.
Simulated verdicts, but the rules are the library's real ones: the type checker rejects wrong/missing proofs; the lint preset rejects forgeries. Real thing: rauchg/gdp-ts (MIT).
Flip between the two layers. The proofs are real to the compiler — and gone by the time your code runs.
compile time — proofs exist
The proofs evaporated. What shipped is just the values and one tiny wrapper — no extra queries, no dependencies, no runtime checks to forget.
Right now you're looking at what the compiler sees: every value carries its name, every sensitive call carries its proof. The ghosts do all their work here.
Rigor is a slider, not a switch. The library is built to be adopted one sensitive function at a time — you choose how much gets exhaustively proven.
Every sharp tool has an edge. The library is honest about its limits — so is this page.