-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Issue with Array.isArray typeguard after upgrading from 4.1.2 to 4.1.3 #41984
Comments
👋 Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of the repro in this issue running against the nightly TypeScript. If something changes, I will post a new comment. Issue body code block by @mwgamble 👍 Compiled Historical InformationIssue body code block by @mwgamble
|
Not to sound rude, but Repro Bot is incorrect. Unless there's something really weird about my setup, this issue is not occurring on This is the playground link for This is the playground link for |
Interesting, wonder what's up with the bot then - it should be the same underlaying code as the playground. Perhaps the repro bot has a default setting set which causes it to act differently. Confirmed that the error occurs on master in a test case too. It can be fixed by reverting this: - // If the candidate type is a subtype of the target type, narrow to the candidate type,
- // if the target type is a subtype of the candidate type, narrow to the target type,
- // otherwise, narrow to an intersection of the two types.
- return isTypeSubtypeOf(candidate, type) ? candidate : isTypeSubtypeOf(type, candidate) ? type : getIntersectionType([type, candidate]);
+ // If the candidate type is a subtype of the target type, narrow to the candidate type.^M
+ // Otherwise, if the target type is assignable to the candidate type, keep the target type.^M
+ // Otherwise, if the candidate type is assignable to the target type, narrow to the candidate^M
+ // type. Otherwise, the types are completely unrelated, so narrow to an intersection of the^M
+ // two types.^M
+ return isTypeSubtypeOf(candidate, type) ? candidate :
+ isTypeAssignableTo(type, candidate) ? type :
+ isTypeAssignableTo(candidate, type) ? candidate :
+ getIntersectionType([type, candidate]); Will remove the error - @weswigham, do you have a good argument for keeping it around? |
Is there an update on this? I can see that some related PRs appear to have been merged. |
The changes should have all been reverted I believe, good reminder to close this out |
@orta is the fix in 4.3 already? If you look at the playground @mwgamble at line 27 the Also, see this playground of mine.
|
TypeScript Version: 4.2.0-dev.20201211
Search Terms:
re:
Array.isArray
Code
Expected behavior:
This code should compile properly without issues. It compiles fine on
4.1.2
and also compiled fine on previous releases going all the way back to at least3.8
.Actual behavior:
I get this output from
tsc
with the command-lineyarn run tsc test.ts
. There is notsconfig.json
file in the folder at the time.Playground Link: https://www.typescriptlang.org/play?ts=4.2.0-dev.20201211#code/JYOwLgpgTgZghgYwgAgCoQM5gMJwxAHlWQgA9IQATDZLKUAc2QB9kQBXAWwCNoA+ZAG8AUMjHIoEOJQD2IADYBPZADc48gIwAuNC2QAlKbIWKAglChxFRPgG5R4ydLlLV6gEw7Dzk+cvXUO2EAX2FhUEhYRBQAWXZ5MGBcfAAxYHJ2SRshBzEEPEwdVABtAF17UOEYdhAERLladm4AETgwOBSahAAKAEoizBwCgjpGPQ4efjKc8QkIMEyQZGLc2aE3TR0AIjgtgBoNz2Wd-eQt7lOthC3S5GC91dnBDe1kdwO1eSPijQP35AAzLd7o9xM9Pq9iicDlsAF43D4eHRQ0iXRSXeHAh5rMEvZEAVgOGgADKVEV9kSSicTidSaVjVuUQmFqrV6ktKG0Ol0bN0ME1OrUdH1kABeAQlUr9ZBxBJJAppDJZQIzRzzRbrfL4DA6fncQU9Xp3Cosrrs5CQLAGkUiWYIORYZAwdILSRi5Cc9oGoiDZKEUYgJisCa8KB8Ph8pqtL1dXr2WbOpUQAB0WswyZgMigAFFEAALbrdcHqX6HO5G8WqnHAGDIbp+KzJ4AYBuKboQ3pG204tb2kCOyQqaD4SgANRL7ohyYw8mASD6ycHw4gfXjPbtDpk8hT8hkDG6S6gI-HmjjoLEwRI8nwVfXyD7GC3O737ZLZ-XoXXD6fyd3+8+7jvuIwRnpUlpgNacZAA
Related Issues:
According to #40463 and #41808, an issue with
Array.isArray
has already been fixed and is supposedly in4.1.3
.The text was updated successfully, but these errors were encountered: