Only resolve source return type when actually needed during inference when generic is used #58926
Closed
6 tasks done
Labels
Needs Investigation
This issue needs a team member to investigate its status.
Suggestion
An idea for TypeScript
Milestone
π Search Terms
"is referenced directly or indirectly in its own type annotation.ts(2502)"
"self-referencing types"
"circular types"
...
β Viability Checklist
β Suggestion
Thanks to @ahejlsberg the issue #58616 was solved and the change works perfectly. Unfortunately my last comment was written too late and got lost among the other comments and issues. The code like this now works:
But in case if generics are used the
arg
wouldn't be recognised as expected, even if we still don't need to infer the return type.π Motivating Example
As you can see the requirement is very similar: we don't need to infer the function type fully, we just need to get the parameters type, and at this example the only argument should clearly be inferred as a string.
π» Use Cases
I work on a back-end library that relies on service-controller-repository pattern. The idea is to return service method call result from a controller, and to make the service method to accept parameters that are inferred from parameters of the controller.
There is what I actually trying to achieve, it's a bit more complex than the previous examples:
VovkControllerBody
infers the JSON body fromController.doSomething
argument defined bywithZod
.The only workaround here is to have Zod schemas somewhere outside of the classes. But it requires to define extra variables and imports making the code less readable in large apps.
Thanks!
The text was updated successfully, but these errors were encountered: