Open this example in the interactive library
Source code
type Brand<T, Name extends string> = T & { readonly __brand: Name };
console.log(
((id: Brand<string, "UserId">, name: string) => ({ id, name }))(
"u1" as Brand<string, "UserId">,
"Ada",
),
);
Sample output
{ id: 'u1', name: 'Ada' }