Skip to content
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(assert): fail type check for assertArrayIncludes when element type of expected not assignable to actual (#6427) #6428

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lionel-rowe
Copy link
Contributor

Fixes #6427

@lionel-rowe lionel-rowe requested a review from kt3k as a code owner February 19, 2025 15:09
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.08%. Comparing base (360851f) to head (314e124).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6428      +/-   ##
==========================================
+ Coverage   96.03%   96.08%   +0.04%     
==========================================
  Files         562      562              
  Lines       42418    42418              
  Branches     6387     6387              
==========================================
+ Hits        40738    40756      +18     
+ Misses       1641     1629      -12     
+ Partials       39       33       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -18,7 +18,7 @@
*
* assertEquals(intersect(lisaInterests, kimInterests), ["Cooking", "Music"]);
*
* assertArrayIncludes(lisaInterests, [sample(lisaInterests)]);
* assertArrayIncludes(lisaInterests, [sample(lisaInterests)!]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this change seems concerning to me (I think this PR will break actual users code in a similar way)

Can we keep this case working without change somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm this change seems concerning to me (I think this PR will break actual users code in a similar way)

Can we keep this case working without change somehow?

I don't think so, without explicitly allowing undefined, which seems wrong.

For comparison, again with Array#includes:

declare let xs: string[]
declare let x: string | undefined

// Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
xs.includes(x)

But on second thoughts, maybe the strict behavior rejecting legitimate uses is more annoying than the sloppy behavior accepting illegitimate ones/lacking autocomplete... it's not uncommon that I have to write code like this:

stringLiteralUnionArr.includes(arbitraryString as typeof stringLiteralUnionArr[number])

@kt3k
Copy link
Member

kt3k commented Feb 20, 2025

While I think this change is aligned to the direction we chose in #2203, I'm also very concerned with the breaking nature of this PR.

cc @bartlomieju @ry

@bartlomieju
Copy link
Member

I tend to agree. Maybe try using this PR in the Deno repo submodule and see how bad it's gonna be?

@kt3k
Copy link
Member

kt3k commented Feb 21, 2025

It turned out that denoland/deno repo doesn't include any usage of assertArrayIncludes

~/denoland/deno $ git grep assertArrayIncludes | wc -l
       0

There seem relatively small number of usages in github search https://github.com/search?q=assertArrayIncludes+language%3ATypeScript&type=code&l=TypeScript

Maybe we can land this as 'fix'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants