How do you call fulfill() with a Void promise? I've looked high and low in the docs and the open/closed issues and couldn't find the answer.
Example code:
func test1() -> Promise<String> {
return Promise<String> { fulfill, reject in
fulfill("Hello")
}
}
func test2() -> Promise<Void> {
return Promise<Void> { fulfill, reject in
fulfill()
}
}
test1() compiles fine
test2() does not compile with this error:
fulfill()
Expression type '(_) -> Void' is ambiguous without more context
Try to return fulfill(()) for Promise<Void> statement.
Yes, fulfill(()). This is not an issue specific to PromiseKit (it is in fact an issue with Swift 4), there are actually maybe 4 or 5 closed issues that ask this question and there are maybe 40 or 50 examples of fulfilling Void promises here on GitHub in the PromiseKit sources, but I will add it to our TroubleShooting documentation.
I actually looked through the closed tickets and code as well but I guess my searching foo isn't so good. Thank you so much. It's frustrating to learn Swift when the syntax changes from version to version!
Changes from 3 to 4 were much less severe so hopefully 4 to 5 will be hardly anything.
Searching tickets can be hard, especially when there are so many, so it's good you opened the ticket as it made me add a proper note in the trouble-shooting guide.
Most helpful comment
Try to return
fulfill(())forPromise<Void>statement.