I'm facing a situation where I have an async function nested inside an object. In order to maintain proper type declarations, I need to structure it like the example below:
interface Props {
loading?: boolean | undefined;
separator?: 'cell' | 'none';
onRequest?: (requestProp: {
pagination: {
sortBy: string;
descending: boolean;
page: number;
rowsPerPage: number;
};
filter: string;
}) => void;
}
const myObj = {
async myTest({ pagination }) { // How do I set myTest as Props['onRequest']?
let $id = this.id;
/* consume $id and await */
/* ... */
},
id: 521,
result: '',
};
Is there a specific way to define the type of a method in an object literal?