1

I'm trying to create a custom RxJS filter operator that takes as a parameter destructured array.

But it seems that typescript is not happy with the type, I'm getting this error:

TS2493: Tuple type '[]' of length '0' has no element at index '0'.


export function customOperator<T extends []>() {
    return pipe(
        filter<T>(([param1, param2, param3])=> {
            //some logic
        })
    );
}
Or Shalmayev
  • 295
  • 1
  • 12
  • That reads like a runtime error. You've written bad code or called this incorrectly. Fixing the types won't change the call-cite. – Mrk Sef Dec 15 '22 at 13:55

1 Answers1

0

You can use the rest operator (...) to unpack the array and then destructure the items. This will allow the compiler to understand that you'll be accessing items in the array.

export function customOperator<T extends []>() {
return pipe(
    filter<T>(([...[param1, param2, param3]])=> {
        //some logic
    })
);
}
  • Hi, Thank you, I tired your solution but it seems that when I'm trying to access properties inside the destructured parameters they all have type of ```never``` ```TS2339: Property 'forceLoad' does not exist on type 'never'.``` – Or Shalmayev Dec 15 '22 at 09:00