Dev Helpers
← Back

Read a value through a branded map key

Read a value through a branded map key using TypeScript.

Open this example in the interactive library

Source code

type Brand<T, Name extends string> = T & { readonly __brand: Name };
console.log(
  new Map<Brand<number, "OrderId">, string>([
    [1 as Brand<number, "OrderId">, "ready"],
  ]).get(1 as Brand<number, "OrderId">),
);

Sample output

ready