-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
then
methods type inferring issue
#44
Comments
I wonder if this is because of the type inference on the value |
@khanlou oh no no, var giftController: Promise<GiftIntroductionController> {
imagePromise.then { userImage in
return GiftIntroductionControllerBackend.make(for: gift, image: userImage)
}.then { backend -> GiftIntroductionController in // Here, type will not be inferred if not specified explicitly
let controller = UIStoryboard.main.instantiate(GiftIntroductionController.self)
controller.prepare(for: backend)
return controller
}
} N.B.: the return type of closure in |
In the example, the issue is that your block is longer than one line, so its type is not inferred. Via the readme:
|
@isaac-weisberg is this good to close now or is there still an issue? |
Still an issue, planned to try to dig more this weekend, if you don't mind :) |
🤔🤔🤔 I am struggling trying to replicate this behavior with Swift 4.1 on Linux |
Alright, evidently, the issue is not with version of Swift, I have tuned test up a bit and it started to appear |
Alright, so first wave of experiments is to be referred to as "done". The compiler was ultimately confused by the following construct. let promise = Promise { fulfill, reject in
fulfill(SomeStuff())
}.then { value in
return Promise { fulfill, reject in
fulfill(Apple(str: "Heoooo"))
}
}.then { apple in
return Bapple.make()
}.then { bapple in
print("Bapple is \(bapple)")
return bapple
} About the last
Observation 1: so we've got 3 Observation 2: third |
So, possible solution:
|
Lol so I tried it Good thing:
Bad thing:
Extract from PromiseTests.swift let promise = Promise(value: "someString").then({ string in
return string.count
}).then({ count in
return count*2
}).then({ doubled in
XCTAssertEqual(doubled, 20)
expectation?.fulfill()
}) Before the changes, type of P.S.: one might be wondering "Hey, Isaac, but did this resolve your issue that you had with type inferring?". Answer is no 😂 |
So obviously, with this change to API, all usages of not-chaining |
I have done this and it looks concise and beautiful but this did not resolve the issue. I will fiddle with is just a bit more, maybe it will work, but there is no reason to presume something is going to get fixed eventually in that regard. |
let promise = Promise { fulfill, reject in
fulfill(SomeStuff())
}.then { value in
return Promise { fulfill, reject in
fulfill(Apple(str: "Heoooo"))
}
}.then { apple in
return Bapple.make()
}.then { bapple in
print("Bapple is \(bapple)")
return bapple
} produces
Well, that was fun while it lasted :) P.S.: Just in case, @khanlou, I understand the dramatic nature of changes that I used to propose and I have no hard feelings about the idea of having my PR rejected :) I can guess, the project wouldn't like to have such a drastic change to the API :) |
There are 3 methods titled
then
on a Promise objectonFulfilled
of the first method returnsVoid
, of the second -NewValue
, and the third -Promise<NewValue>
, that's important.If you were to write
then it's dandy, the
Void
is returnedIf you were to write
then it's also dandy, the swiftc will figure out that the return type is Promise
However
never just works on its own; there is an issue with type inference and compiler errors with "expected type Promise<_>"
The way you do it so it gets figured out is
Then it's alright.
Observed in XCode 9.2 GM, Swift 4.0.2
Also observed in Swift 4.0.3 environment on Linux.
Possible solution
It may or may not help to rename the handler from
onFulfilled
to a different name such asonFulfilledWithValue
in the method where handler returnsNewValue
.The text was updated successfully, but these errors were encountered: