Description
Summary
OkObjectResult has an inner type of object?. This proposal is to make it generic, allowing better type safety when used in conjunction with ActionResult
Motivation and goals
Currently it is possible to break type safety in a method that returns an ActionResult. See the code sample below, found in a controller.
[HttpGet()]
public ActionResult<T1> MyControllerMethod {
T2 myResult = repository.get();
return Ok(myResult);
}
This code not only compiles, but creates API endpoints whose swagger documentation represents T1, when the returned type is actually T2. This is clearly unintended.
The goal here is to not change the signature of the helper functions like Ok(), but to use generics and type inference to ensure that types flow through the system properly.
Risks / unknowns
Some API's could theoretically build only because of this issue. While this would not be a hard thing for developers to fix, this would be a breaking change due to some projects not building after the types are locked down.