Type Errors
Type Errors
Dependency Expecting a Child
We can't use the repository for finding data:
Solving Type Errors
Transforming the Input
If we want to keep the interface then we need to transform the input object into a valid type.
There are two cases here:
We have received an instance of the expected type, but the interface hides it
We have received an instance of another type
In the first case we only need to cast the input. But in the other one we have to copy the properties into a new instance.
Adding a Type
If we can change the interface another option is adding the type by using generics.
While this solves the problems, it also means that we will need a version of the service for each type.
When using dependency injection we will need to take care of the type, making it harder to swap one version of the service for another.
Last updated
Was this helpful?