Skip to content

Instantly share code, notes, and snippets.

@bcherny
Created August 20, 2019 04:11
Show Gist options
  • Save bcherny/3e73b5c8da3c5a85ed1448c4a33222b8 to your computer and use it in GitHub Desktop.
Save bcherny/3e73b5c8da3c5a85ed1448c4a33222b8 to your computer and use it in GitHub Desktop.
/////////////// 1ST CODE SAMPLE (PAGE 140) ///////////////
type Unit = 'EUR' | 'GBP' | 'JPY' | 'USD'
type Currency = {
unit: Unit
value: number
}
let Currency = {
from(value: number, unit: Unit): Currency {
return {
unit: unit,
value
}
}
}
/////////////// 2ND CODE SAMPLE (PAGE 140) ///////////////
import {Currency} from './Currency'
let amountDue: Currency = {
unit: 'JPY',
value: 83733.10
}
let otherAmountDue = Currency.from(330, 'EUR')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment