Created
December 15, 2016 17:38
-
-
Save OliverJAsh/93f636ed3af2721e41a2101f04e01e43 to your computer and use it in GitHub Desktop.
TypeScript key lookup helpers
This file contains hidden or 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
export type Maybe<T> = undefined | T; | |
export type StringDictionary<T> = { [k: string]: T }; | |
export const getInDictionary = <T>(dict: StringDictionary<T>, prop: string): Maybe<T> => dict[prop] | |
export const getInArray = <T>(array: T[], index: number): Maybe<T> => array[index] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment