tusken
tusken copied to clipboard
Type brands for primary/foreign keys
Goal: Extra type safety. Prevent primary keys for one table from being used in a query of another table.
// The generated type of a primary/foreign key
id: t.int4 & t.key<'user.id'>
To convert an external value into a branded key:
// Note: Falsy values are passed through.
const userId = t.user.id(req.searchParams.get('userId'))
Casting like what's shown above doesn't include runtime validation. This is only for type safety.