Created
September 14, 2018 08:21
-
-
Save muuki88/a964a33f2b11f3b664a04f04f7f4b85e to your computer and use it in GitHub Desktop.
KeyValue Storage
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 KeyValueStorage = { | |
'setting1': boolean; | |
'setting2': string; | |
'setting3': number; | |
}; | |
/** all possible keys for the key-value storage */ | |
type KeyValueStorageKey = keyof KeyValueStorage; | |
interface UserStorage { | |
/** set a value for a specific key */ | |
set<T extends KeyValueStorageKey>(key: T, value: KeyValueStorage[T]): void; | |
/** get the value for a specific key. If not present return null*/ | |
get<T extends KeyValueStorageKey>(key: T): KeyValueStorage[T] | null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment