Dev Helpers
← Back

Add amounts in the same currency

Add amounts in the same currency using TypeScript.

Open this example in the interactive library

Source code

type Brand<T, Name extends string> = T & { readonly __brand: Name };
console.log(
  ((a: Brand<number, "CAD">, b: Brand<number, "CAD">) =>
    (a + b) as Brand<number, "CAD">)(
    20 as Brand<number, "CAD">,
    5 as Brand<number, "CAD">,
  ),
);

Sample output

25