I am facing a challenge with the function below and its callback type:
type Callbacks = {
onSuccess: (a: string) => void;
};
function myFunction(event: string, ...args: [...any, Callbacks]) {
}
The function works correctly except for one issue - the onSuccess
function has a parameter of type string but TypeScript is unable to recognize it and considers it as any type even though I have explicitly set it to string.
myFunction("eventName", "bobo", 123, {onSuccess: (asd) => {
// "asd" should be a string but TypeScript treats it as any
// Parameter 'asd' implicitly has an 'any' type
}})
What adjustments can I make to enable TypeScript to identify the type of parameters in the callbacks without manually specifying them each time?
P.S. This example is a simplified version of the actual problem I am encountering.