Created
December 14, 2021 13:43
-
-
Save peterhudec/04caffa47f891c34ac2ae8aaf45f9358 to your computer and use it in GitHub Desktop.
FX Asset Classes Typing
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 Currency = 'USD' | 'EUR' | 'CZK' | |
type PreciousMetal = `X${ 'AG' | 'AU' | 'PD' | 'PT' }` | |
type Treasury = `T${`0${ 2 | 3 | 5 | 7 }` | `${ 1 | 2 | 3 }0`}` | |
type CurrencyCurrency = `${Currency}${Currency}` | |
type PreciousMetalCurrency = `${PreciousMetal}${Currency}` | |
type TreasuryCurrency = `${Treasury}${Currency}` | |
type InstrumentNames = CurrencyCurrency | PreciousMetalCurrency | TreasuryCurrency | |
type AssetClass<T> = T extends `X${string}` | |
? 'PreciousMetal' | |
: T extends `T${'0' | '1' | '2' | '3'}${string}` | |
? 'Treasury' | |
: 'FX' | |
type PM = AssetClass<'XAUUSD'> | |
type T = AssetClass<'T10USD'> | |
type FX = AssetClass<'foo'> | |
type Instruments = { | |
[K in InstrumentNames]: AssetClass<K> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment