requireDictionaryItem()function

requireDictionaryItem(dict: ImmutableDictionary<T>, key: string, caller: AnyCaller = requireDictionaryItem): T
ParamType
dictImmutableDictionary<T>
The dictionary to read the item from. required
keystring
The key of the item to read. required
callerAnyCaller
Function to attribute a thrown error to (defaults to requireDictionaryItem itself). Defaults to requireDictionaryItem
Return
T
The value of the item.
Throws
RequiredError
If key is not an own prop of dict.

Get an item in a dictionary object, or throw RequiredError if it doesn't exist.

Examples

requireDictionaryItem({ a: 1 }, "a"); // 1