Conversation
|
@sandersn Thank you for submitting this PR! 🔔 @lhecker @nickiannone @asvetliakov @newraina - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
|
@sandersn The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
types/bluebird/bluebird-tests.ts
Outdated
|
|
||
| // $ExpectType Bluebird<void | Foo> | ||
| fooProm.catch(Error, (reason: any) => { | ||
| fooProm.catch(Error as { new(message?: string): Error }, (reason: any) => { |
There was a problem hiding this comment.
I don't quite understand the changes to this file. Can you explain to me why they're necessary?
(I haven't been following the latest changes in TS 3.2. 🤐)
I'm asking because because these particular tests assert the proper functionality of one of Bluebird's features.
As such it's important that the Bluebird typings work even if you keep this test file as it is.
Would it be possible to change the actual typings instead?
There was a problem hiding this comment.
Error actually appears to match two of the possible filter types: class ErrorClass and function (anyOtherError), but the second match is incorrect. The typescript representation is
type CatchFilter<E> = (new (...args: any[]) => E) | ((error: E) => boolean)
interface ErrorConstructor {
new(message?: string): Error;
(message?: string): Error;
}Inferring from the construct signature gives E=Error, and inferring from the call signature gives E=string | undefined. I'm not sure why pre-3.2 Typescript used the first inference instead of the second.
There was a problem hiding this comment.
The change happened in microsoft/TypeScript#27028, which changed the way co- and contra-variant inferences work so that contravariant inferences (callback parameters like (error: E) => boolean) are preferred over covariant inferences (return positions like new (...args:any[]) => E).
I think this is the right change for most cases, so I'll see if I can find a workaround for this case.
There was a problem hiding this comment.
Ah I see... That's of course very unfortunate since we were relying on the CatchFilter preferring covariants / the constructor signature. 😟
It'd be nice if we could come up with a solution that properly resolves this. 🤔
I'll try to come up with something as well, although I'm not as versed in typescript as I used to.
There was a problem hiding this comment.
Well, I can manually promote the constructor inferences by breaking catch into more overloads. I'm trying that now to make sure it works and see how ugly it is.
There was a problem hiding this comment.
If it works I'm absolutely happy with it. 🙂
Meanwhile I tried:
type CatchFilter<E> = E extends InstanceType<infer R> ? R : (((error: E) => boolean) | (object & E));But it doesn't work: It still resolves to / picks the latter half and thus fails the type check.
I thought this ternary-like operator would actually behave like a classic ternary operator and be evaluated eagerly. But instead it seems that it's resolved just like the regular union operator?
1. Use 3.1 and 3.2-compatible fix for match-media-mock. Specify a this-parameter. 2. redux-action requires TS 2.3 so that type parameter defaults and mapped types from redux 4.0 work.
|
@sandersn One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you! |
|
🔔 @lhecker - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
Notes: 1. I only duplicated overloads to get 2 * n instead of 2 * n overloads needed to support every combination of constructor function/other. 2. I deleted the duplicate R vs U | R overloads for `catch` since they were equivalent; I don't think the R overloads were ever used. 3. The original overload is now Constructor<E> | CatchFilter<E>; I haven't figured out why yet, but normal classes don't use the new Constructor<E>-only overload. Only constructor functions do.
|
Well, I created more overloads. There are some caveats that come with this commit:
@weswigham Any clever ideas here? |
|
I believe the Anyways... Thanks for the changes. 🙂 |
lhecker
left a comment
There was a problem hiding this comment.
I'm approving this already in order to not block you any further until you've resolved the remaining CI issues, as I'm probably preoccupied in the next 2 days or so. 🙂
|
Thanks; it's just the linter warning me that overlapping overloads is a bad idea. I'll need to silence it if I decide to take this approach. Tagging @DanielRosenwasser for clever workaround ideas too. |
|
@sandersn The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
|
@sandersn I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues. |
|
@sandersn To keep things tidy, we have to close PRs that aren't mergeable but don't have activity from their author. No worries, though - please open a new PR if you'd like to continue with this change. Thank you! |
|
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
Note that all changes are to tests, except for the update to redux 4.0 in redux-action's package.json.