Why can't typescript infer tuple return type in RxJs stream?
In your map
function, you are returning an array, not tuple.
You can use as const
to force the tuple type:
export class AppComponent {
observable$ = from([new MyType('obj1'), new MyType('obj2')]).pipe(
map((value, index) => [value, index] as const),
tap(([value, index]) => console.log(value, index))
).subscribe();
}
See Tuple Types:
array literals with
const
assertions will be inferred withreadonly
tuple types