Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created December 15, 2016 17:38
Show Gist options
  • Save OliverJAsh/93f636ed3af2721e41a2101f04e01e43 to your computer and use it in GitHub Desktop.
Save OliverJAsh/93f636ed3af2721e41a2101f04e01e43 to your computer and use it in GitHub Desktop.
TypeScript key lookup helpers
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