Skip to content

Instantly share code, notes, and snippets.

@muuki88
Created September 14, 2018 08:21
Show Gist options
  • Save muuki88/a964a33f2b11f3b664a04f04f7f4b85e to your computer and use it in GitHub Desktop.
Save muuki88/a964a33f2b11f3b664a04f04f7f4b85e to your computer and use it in GitHub Desktop.
KeyValue Storage
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