-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Added type guard overload ReadonlyArray.prototype.every #18372
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
Conversation
Do the test.symbols and the test.types files not get generated if there are errors? Is there a better way of testing for errors so that those still get generated? |
f8887c1
to
cadf438
Compare
const numberReadonlyArray: ReadonlyArray<number> = baseReadonlyArray; // should be ReadonlyArray<number> | ||
} | ||
|
||
if (baseReadonlyArray.every((x): x is number => "number" === typeof x)) { |
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.
OK, something's not working with the inference...?
Correct. Best practice is to have one testcase with all the error cases, and one testcase with zero errors. This is also better for future reviews since a file going from 0 to 1 errors will raise a red flag more quickly than a file going from e.g. 4 to 5. |
cadf438
to
e5a85e7
Compare
OK, in the current state, there should be no errors. For some reason it's not working if the type parameter isn't specified explicitly. I'm not sure what the issue is. |
e5a85e7
to
ffd2d13
Compare
OK, the issue was #18562, I've used a workaround, the tests pass as they should. This PR should be mergeable as it is now. |
…rd if the callback is one. Fixes microsoft#14963
ffd2d13
to
fc29212
Compare
@RyanCavanaugh any comment on the current state of the PR? |
@mhegazy 👍 ? |
We should have a similar change in Array as well. Array and ReadonlyArray should stay in sync. |
@mhegazy Does that make sense? according to the linked issue
... although tbh you can get the same prob with a ReadonlyArray with only slightly more effort. |
@mhegazy Considering my last comment, this should be mergeable as-is? Or do we want to revisit the original issue? |
@NaridaL Hope this get merged soon. Relying on |
I think we're just waiting on having the appropriate overload in |
Sorry for the late reply. i do not see why we should not do that for |
|
This is a language issue then. TypeScript compiler have to track every reference assignment. More static analysis-like thing. Out of our hands now I suppose. |
Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it. |
@mhegazy I just hit this now, would you like an updated PR with the I noticed |
Fixes #14963