You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{AsyncIterableX,from}from"ix/asynciterable";import{tap}from"ix/asynciterable/operators";import{MonoTypeOperatorAsyncFunction,MonoTypeOperatorFunction,}from"ix/interfaces";import{IterableX}from"ix/iterable";declareconstsync: IterableX<number>;declareconstasync: AsyncIterableX<number>;declareconstsyncOp: MonoTypeOperatorFunction<string>;declareconstasyncOp: MonoTypeOperatorAsyncFunction<string>;sync.pipe(syncOp);// ~~~~~~ Errors, as it shouldasync.pipe(asyncOp);// ^^^^^^^ No error!// Demo, will crash at runtimefrom([1,2,3]).pipe(tap((val: string)=>val.length));
Expected behavior: The function signature should prevent piping an AsyncIterable<number> into an operator that expects string. The attached code demonstrates how this could end up bad.
Actual behavior: According to TS, the expression is a-ok for async iterables. Note that it works as intended for sync iterables.
Additional information:
The text was updated successfully, but these errors were encountered:
Thanks for the report, this definitely seems odd. What version of typescript are you using?
Minor annoyance in that the sync.pipe() call is decaying to the WritableStream case:
No overload matches this call.
The last overload gave the following error.
Argument of type 'MonoTypeOperatorFunction<string>' is not assignable to parameter of type 'WritableStream'.ts(2769)
But at least TS is inferring the OperatorFunction<T, R> correctly:
In the AsyncIterable case, it's decaying to OperatorAsyncFunction<any, any>, and I'm not sure why:
We've been through a few TS upgrades since these signatures were written, there may be a better way to write this now. I'll investigate.
IxJS version: 7.0.0
Code to reproduce: https://codesandbox.io/p/sandbox/typescript-playground-export-forked-9jmsj9?workspaceId=ws_TdkXAMqyc14LovZfzuJaP6
Expected behavior: The function signature should prevent piping an
AsyncIterable<number>
into an operator that expectsstring
. The attached code demonstrates how this could end up bad.Actual behavior: According to TS, the expression is a-ok for async iterables. Note that it works as intended for sync iterables.
Additional information:
The text was updated successfully, but these errors were encountered: