This compiles:
typealias AnyDict = [String : Any]
extension URLSession {
func httpQuery<T>(_ url: URL) async throws -> T {
...
}
}
struct TVInfo {
init(data: AnyDict) throws { ... }
...
}
func queryForTVs() async throws -> [TVInfo] {
let deviceData: [AnyDict] = try await urlSession.httpQuery(url)
return try deviceData.map { try TVInfo(data: $0) }
}
This does not:
func queryForTVs() async throws -> [TVInfo] {
try await urlSession.httpQuery(url).map { try TVInfo(data: $0) }
}
I would expect the second example to work via type inference: it is clear that map is taking an AnyDict, so the generic variable for httpQuery is clear. But I get an error like:
Invalid conversion from throwing function of type '(AnyDict) throws ->TVInfo' (aka '(Dictionary<String, Any>) throws -> TVInfo') to non-throwing function type '(AnyDict) -> AppleTVInfo' (aka '(Dictionary<String, Any>) -> TVInfo')