Created
July 19, 2019 10:37
-
-
Save resynth1943/65f5eb3e13233b2a3b62e6cd59f98e87 to your computer and use it in GitHub Desktop.
TypeScript - Opaque Types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Opaque<V> = V & { readonly __opq__: unique symbol }; | |
type AccountNumber = Opaque<number>; | |
type AccountBalance = Opaque<number>; | |
function createAccountNumber (): AccountNumber { | |
return 2 as AccountNumber; | |
} | |
function getMoneyForAccount (accountNumber: AccountNumber): AccountBalance { | |
return 4 as AccountBalance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment