Module "operators/throw-if-undefined"
Functions
throwIfUndefined
- throwIfUndefined<T>(errorFn: (value: T, index: number) => any): OperatorFunction<T, Exclude<T, undefined>>
-
Type parameters
Parameters
-
errorFn: (value: T, index: number) => any
-
- (value: T, index: number): any
Returns OperatorFunction<T, Exclude<T, undefined>>
Throws the error built by
errorFn
if the current value isundefined
. Performs type narrowing and removes undefined from your value type.const input = of(value as string | undefined); const result = input.pipe( map(v => v) // typeof v = string | undefined throwIfUndefined(() => 'error'), map(v => v) // typeof v = string );