# Allow TaskGroup's ChildTaskResult Type To Be Inferred

**URL:** <https://forums.swift.org/t/allow-taskgroups-childtaskresult-type-to-be-inferred/72175>\
**Category:** Discussion\
**Created:** [May 30, 2024, 6:16pm UTC](https://forums.swift.org/t/allow-taskgroups-childtaskresult-type-to-be-inferred/72175 "2024-05-30T18:16:52Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ktoso](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ktoso/32/44526_2.png) [@ktoso](https://forums.swift.org/u/ktoso)\
**Post date:** [June 3, 2024, 12:37pm UTC](https://forums.swift.org/t/allow-taskgroups-childtaskresult-type-to-be-inferred/72175/4 "2024-06-03T12:37:54Z")

</div>

> [@jim](#):
>
> Question: How would errors be caught if we create Tasks with different return types? How would this surface in the IDE? Would it possibly more confusing than having a “ground truth” at the top of the statement?

My snippet pasted above directly answers this question, the error you get is the following (on that specific line):

> [@ktoso](#):
>
> ```swift
> await withTaskGroup { group in
> group.addTask {
> ""
> }
> group.addTask {
> 12 // pretty good error: Cannot convert value of type 'Int' to closure result type 'String'
> }
> }
> 
> ```

You could still spell it out as `withTaskGroup(of: String.self)`.

* * *

I'm pretty supportive of this, just need to verify if there's some unpredicted problem with this in practice.

We should also keep in mind that once we get [`~Escapable` types](https://forums.swift.org/t/pitch-non-escapable-types-and-lifetime-dependency/69865) I hope we'll be able to get rid of the "with" in the API entirely, since an un-escapable task group could -- potentially -- then just be initialized:

```swift
func test() async {
  var group = TaskGroup(of: Int.self) // : ~Escapable 
  group.addTask {}

```

in which case I think the `of` isn't as confusing as it might be with the `with...` style tbh...

So that's another thing to consider as we evolve these APIs to become more ergonomic.

---

_[View the full topic](https://forums.swift.org/t/allow-taskgroups-childtaskresult-type-to-be-inferred/72175)._
