Utility library providing RxJS operators.
npm install @mjamsek/rxjs-utilsnpm install --save @mjamsek/rxjs-utils
assertType() asserts observable is of type T. Usage:
typescript
observable$.pipe(
assertType(),
);
`
#### Assert void
assertVoid() asserts observable is of type void. Usage:
`typescript
observable$.pipe(
assertVoid(),
);
`
#### Assert non null
nonNull() asserts observable value is not null. Usage:
`typescript
observable$.pipe(
nonNull(),
);
`
#### Type filter
ofTypeOnly runs a type guard check on observable to filter values that are not of type T. Usage:
`typescript
function isString(x: unknown): x is string {
return typeof x === "string";
}
observable$.pipe(
ofTypeOnly(isString),
);
`
You can also create reusable filters, by using createTypeFilter function:
`typescript
const enforceString = createTypeFilter(isString);
observable$.pipe(
enforceString(),
);
`
#### Enforce type
enforceType runs a type guard check on observable to enforce it is of type T. Usage:
`typescript
function isString(x: unknown): x is string {
return typeof x === "string";
}
observable$.pipe(
enforceType(isString),
);
`
You can also create reusable enforcers, by using createTypeEnforcer function:
`typescript
const enforceString = createTypeEnforcer(isString);
observable$.pipe(
enforceString(),
);
``