-
Notifications
You must be signed in to change notification settings - Fork 72
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
fix: typedef default onfulfilled handler for E.when #1233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -46,3 +46,26 @@ const foo2 = async (a: FarRef<{ bar(): string; baz: number }>) => { | |||||||
// @ts-expect-error - calling directly is valid but not yet in the typedef | ||||||||
a.bar; | ||||||||
}; | ||||||||
|
||||||||
// when | ||||||||
const aPromise = Promise.resolve('a'); | ||||||||
const onePromise = Promise.resolve(1); | ||||||||
const remoteString: ERef<string> = Promise.resolve('remote'); | ||||||||
E.when(Promise.all([aPromise, onePromise, remoteString])).then( | ||||||||
([str, num, remote]) => { | ||||||||
Comment on lines
+54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem here is likely in a misusage of
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but I think it's optional in the sense that the expectation is to use either onfulfilled or onrejected. Using That said, to enable this case with the types, I do believe that defaulting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "expectation" and "anti-pattern" are fuzzy to me wrt the type defs. The type checker has only errors not warnings :) If you think the type should require at least one handler, I can define the type that way. Though I think you're saying that it should allow them both to be omitted and your solution sounds right. I'll try it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Speaking only for |
||||||||
expectType<string>(str); | ||||||||
expectType<number>(num); | ||||||||
expectType<string>(remote); | ||||||||
}, | ||||||||
); | ||||||||
E.when( | ||||||||
Promise.all([aPromise, onePromise, remoteString]), | ||||||||
([str, num, remote]) => { | ||||||||
expectType<string>(str); | ||||||||
expectType<number>(num); | ||||||||
expectType<string>(remote); | ||||||||
return { something: 'new' }; | ||||||||
}, | ||||||||
).then(result => { | ||||||||
expectType<{ something: string }>(result); | ||||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're adding
when
type tests, do you mind also adding a test for the "normal" use case with aonfulfilled
callback?