OkObjectResult should be changed to support better type safety #32080
Labels
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
design-proposal
This issue represents a design proposal for a different issue, linked in the description
✔️ Resolution: Duplicate
Resolved as a duplicate of another issue
Status: Resolved
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.
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.
The text was updated successfully, but these errors were encountered: