feat(expect, @jest/expect-utils): allow isA utility to take a type argument#13355
feat(expect, @jest/expect-utils): allow isA utility to take a type argument#13355SimenB merged 2 commits intojestjs:mainfrom mrazauskas:feat-isA-type-arg
isA utility to take a type argument#13355Conversation
| } | ||
|
|
||
| export function isImmutableList(maybeList: any) { | ||
| return !!( |
There was a problem hiding this comment.
This and following changes comes from Prettier. CI does not catch them, because of /* eslint-disable */ in this file.
There was a problem hiding this comment.
ah, then we should make sure to include this file in https://github.com/facebook/jest/blob/8759d63787b832af1fc9ac0ec2cc57b6f325ba9a/package.json#L103
There was a problem hiding this comment.
Just check, I will send a separate PR removing that comment. Seems doable.
There was a problem hiding this comment.
we have purposefully not been running eslint on it to keep the diff from the jasmine equivalent down.
That might not be relevant 6-7 years later
| asymmetricMatch(other: unknown) { | ||
| const result = isA<string>('String', other) && other.includes(this.sample); |
There was a problem hiding this comment.
This is just an internal type, user facing external types do not change. The point is that internally other is of type unknown in all the matchers. As an illustration see this test (all matchers have similar tests and that is a problem for typechecking):
At first it sounded strange, but reasons are very well explained in #7107
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
While working on typechecks of
expecttypes, I found out that it would be useful to allowisAutility to take a type argument. This changes turns it into a type guard and could be used for type narrowing.Test plan
Type tests are added.