Custom operator affects prevoius operator. #6484
-
Hi, I'm trying to make custom operators, but it messes up typings. What am I missing or doing wrong? export function isBlack(): OperatorFunction<Fruit | Fish, boolean> {
return source => source.pipe(map(v => v.color === 'black'));
} When i use it in a pipe, it messes up the previous tap's typing. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The typing is incorrect on your custom operators. export function isBlack(): OperatorFunction<Fruit | Fish, boolean> {
return source => source.pipe(map(v => v.color === 'black'));
} This implies that your operator will return export function isBlack<T extends Fruit | Fish>(): OperatorFunction<T, boolean> {
return source => source.pipe(map(v => v.color === 'black'));
} This allows Your previous example will allow anything to be passed in and Updated typing |
Beta Was this translation helpful? Give feedback.
The typing is incorrect on your custom operators.
This implies that your operator will return
Fruit | Fish
.What i think you want to do is this
This allows
Fruit | Fish
to be passed in and whatever one is passed is also returned.Your previous example will allow anything to be passed in and
hard
setting the return to a "new" typeFruit | Fish
Updated typing
Stackblitz example