I'm relatively new to Typescript and have managed to add typings to about 90% of my codebase. However, I'm struggling with rest/spread operators. While going through our code today (which I didn't write), I came across this snippet that doesn't seem to work:
interface searchClient {
searchForValues({
name,
query,
...qp,
}: {
name: string;
query: string;
qp: QpInterface; //???this part doesn't work
}): Promise<any>;
}
interface QpInterface {
page?: number;
hits?: number;
attributes?: string;
}
The issue lies in the fact that qp
is defining the key's name in the type instead of typing the ...qp
section as intended. Each key/value pair within ...qp
should be typed by the QpInterface.
Below is an example function call:
this.searchClient.searchForValues({
name: 'title',
query: 'little sheep',
page: 5,
hits: 2
});
I couldn't find sufficient information on this in the documentation. I've tried using ...qp: QpInterface;
and ...QpInterface;
without success. Can anyone suggest the correct way to type ...qp
in the argument?