Below is a service definition:
export class MyService {
doSomething(callbacks: { onSuccess: (data: Object) => any, onError: (err: any) => any }) {
// Function performs an action
}
}
This service is utilized in a component as shown below:
export class MyComponent implements OnInit {
someFunction(): void {
this.myService.doSomething(
{
onSuccess(data: Object) {
onSuccessFunction(data) // Error occurs here
},
onError(err: any) {
}
}
)
}
onSuccessFunction(data: Object) {
}
}
In the code snippet above, onSuccessFunction
is defined within MyComponent
and called inside the anonymous function onSuccess
. However, TypeScript is throwing the following error message:
Property 'initActiveOrders' does not exist on type '{ onSuccess: (data: Object) => any; onError: (err: HttpErrorResponse) => any; }'.ts(2339)
What could be the possible reason behind this error?