import { isNullOrUndefined } from 'util' ; /**
 * Retrieves a property by name from an object and checks that it's not null and not undefined.  It is strongly typed
 * for the property and will give a compile error if the given name is not a property of the source.
 */ export function nonNullProp < TSource , TKey extends keyof TSource > ( source , name ) { const value = < NonNullable < TSource [ TKey ] > > source [ name ] ; return nonNullValue ( value , < string > name ) ; } /**
 * Validates that a given value is not null and not undefined.
 */ export function nonNullValue < T > ( value , propertyNameOrMessage ? ) { if ( isNullOrUndefined ( value ) ) { throw new Error ( 'Internal error: Expected value to be neither null nor undefined' + ( propertyNameOrMessage ? `: ${ propertyNameOrMessage }` : '' ) ) ; } return value ; } /**
 * Validates that a given object is not null and not undefined.
 * Then retrieves a property by name from that object and checks that it's not null and not undefined.  It is strongly typed
 * for the property and will give a compile error if the given name is not a property of the source.
 */ export function nonNullValueAndProp < TSource , TKey extends keyof TSource > ( source , name ) { return nonNullProp ( nonNullValue ( source , < string > name ) , name ) ; }