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