Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 298 Bytes

brand.md

File metadata and controls

19 lines (14 loc) · 298 Bytes

Branding

type Brand<K, T> = K & { __brand: T }

type USD = Brand<number, 'USD'>

function printUSD(usd: USD): void {
  console.log(`amount is ${usd}`)
}

const usd = 10 as USD
printUSD(usd)
printUSD(10) // Doesn't work

function createUSD(value: number): USD {
  return value as USD
}