[GH-ISSUE #722] Type of expression is ambiguous without a type annotation when using response in TokenSuccess #469

Closed
opened 2026-03-03 16:48:54 +03:00 by kerem · 2 comments
Owner

Originally created by @niskah-media on GitHub (Sep 7, 2024).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/722

Description:

Error Type of expression is ambiguous without a type annotation when I try to use response.data in completion handler of authorize() function.

let _ = self.oauthswift.authorize(
            withCallbackURL: InstagramClient.callbackUrl,
             scope: "user_profile,user_media",
             state:state,
             codeChallenge: codeChallenge,
             codeChallengeMethod: "S256",
             codeVerifier: codeVerifier
         ) { [weak self] result in
             switch result {
                case .success(let (credential, response, _)):
                     do {
                         let jsonData = try JSONDecoder().decode(InstagramApiUser.self, from: response.data)
                         print(jsonData)
                         self.keychain[InstagramClient.keychain_credential_key, .archive] = credential
                         self.oauthswift.client.credential.oauthToken = credential.oauthToken
                         self.isAuthenticated = true
                         onSuccess()
                     } catch let error {
                         onFailure(error)
                     }
                 case .failure(let error):
                    onFailure(error)
             }
         }

if I replace response.data by Data()

OAuth Provider? (Twitter, Github, ..):

Instagram

OAuth Version:

  • Version 1
  • Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • head
  • v2.1.0
  • v2.0.0
  • v1.4.1
  • other: (Please fill in the version you are using.)

Xcode version:

  • 11.4 (Swift 5.2)
  • 11.x (Swift 5.1)
  • 10.x (Swift 5.0)
  • other: (Please fill in the version you are using.)
    Xcode 15.2
  • objective c
Originally created by @niskah-media on GitHub (Sep 7, 2024). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/722 ### Description: Error `Type of expression is ambiguous without a type annotation` when I try to use response.data in completion handler of `authorize()` function. ``` let _ = self.oauthswift.authorize( withCallbackURL: InstagramClient.callbackUrl, scope: "user_profile,user_media", state:state, codeChallenge: codeChallenge, codeChallengeMethod: "S256", codeVerifier: codeVerifier ) { [weak self] result in switch result { case .success(let (credential, response, _)): do { let jsonData = try JSONDecoder().decode(InstagramApiUser.self, from: response.data) print(jsonData) self.keychain[InstagramClient.keychain_credential_key, .archive] = credential self.oauthswift.client.credential.oauthToken = credential.oauthToken self.isAuthenticated = true onSuccess() } catch let error { onFailure(error) } case .failure(let error): onFailure(error) } } ``` if I replace `response.data` by `Data()` ### OAuth Provider? (Twitter, Github, ..): Instagram ### OAuth Version: - [ ] Version 1 - [x] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Swift Package Manager - [ ] Manually ### Library version: - [x] head - [ ] v2.1.0 - [ ] v2.0.0 - [ ] v1.4.1 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [ ] 11.4 (Swift 5.2) - [ ] 11.x (Swift 5.1) - [ ] 10.x (Swift 5.0) - [x] other: (Please fill in the version you are using.) Xcode 15.2 - [ ] objective c
kerem closed this issue 2026-03-03 16:48:54 +03:00
Author
Owner

@phimage commented on GitHub (Sep 7, 2024):

no line of error, a lot of code that are not this project, I close

<!-- gh-comment-id:2336405043 --> @phimage commented on GitHub (Sep 7, 2024): no line of error, a lot of code that are not this project, I close
Author
Owner

@phinnaeus commented on GitHub (Feb 25, 2026):

Hi @niskah-media not sure if you ever got this resolved but I ran into the same issue. It's not a bug with OAuthSwift. You just need to avoid the inline tuple destructuring. Instead of destructuring the TokenSuccess tuple inline like this:

oauthswift.authorize(withCallbackURL: url, scope: scope, state: state) { result in
    switch result {
    case let .success((credential, response, _)):
        response.data  // "type of expression is ambiguous"
    ...
    }
}

Give the closure an explicit type and access tuple members by name:

let handler: OAuthSwift.TokenCompletionHandler = { result in
    switch result {
    case .success(let tokenSuccess):
        let credential = tokenSuccess.credential
        let response = tokenSuccess.response
        response?.data  // works fine
    case .failure(let error):
        // handle error
    }
}
_ = oauthswift.authorize(
    withCallbackURL: url,
    scope: scope,
    state: state,
    completionHandler: handler
)

Hope this helps even though it's been a long time :D

<!-- gh-comment-id:3962416256 --> @phinnaeus commented on GitHub (Feb 25, 2026): Hi @niskah-media not sure if you ever got this resolved but I ran into the same issue. It's not a bug with OAuthSwift. You just need to avoid the inline tuple destructuring. Instead of destructuring the TokenSuccess tuple inline like this: ``` oauthswift.authorize(withCallbackURL: url, scope: scope, state: state) { result in switch result { case let .success((credential, response, _)): response.data // "type of expression is ambiguous" ... } } ``` Give the closure an explicit type and access tuple members by name: ``` let handler: OAuthSwift.TokenCompletionHandler = { result in switch result { case .success(let tokenSuccess): let credential = tokenSuccess.credential let response = tokenSuccess.response response?.data // works fine case .failure(let error): // handle error } } _ = oauthswift.authorize( withCallbackURL: url, scope: scope, state: state, completionHandler: handler ) ``` Hope this helps even though it's been a long time :D
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#469
No description provided.