¿Por qué pierdo el tipo en mi función de pipe ? ¿Cómo arreglar eso?
La propiedad 'n' no existe en el tipo '{}'
import { of, map, Observable, Subject, pipe, tap } from 'rxjs'; import { exhaustMap, withLatestFrom } from 'rxjs/operators'; const action = new Subject<{ n: number }>(); const id$ = of(1); const bar = () => pipe( withLatestFrom(id$), exhaustMap(([{ n }, id]) => of([n, id])), // <--- Property 'n' does not exist on type '{}' tap(() => { console.log('in bar pipeline'); }) ); const foo = action.pipe(bar()); foo.subscribe(); action.next({ n: 1 });pipe infiere todos los tipos a partir de los parámetros pasados. Eche un vistazo a https://github.com/ReactiveX/rxjs/blob/master/src/internal/util/pipe.ts
Intente especificar el tipo para el primer parámetro para la inferencia automática para todos.
withLatestFrom<{ n: number }, number[]>(id$),Agregue el tipo de datos adecuado:
const bar = () => pipe( withLatestFrom(id$), exhaustMap(([{ n }, id]: [ {n: number}, number ]) => of([n, id])) tap(() => { console.log('in bar pipeline'); }) );