-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
chore: upgrade biomejs to 1.9.4 #7533
base: unstable
Are you sure you want to change the base?
Conversation
Major change in this PR is rule nursery/useAtIndex. But the change is very important as it improves the type safety. const myArray: number[] = []
// Resolved to type `number`
const lastElement1 = myArray[myArray.length - 1];
// Resolved to type `number | undefined`
const lastElement2 = myArray.at(-1); As you notice in the first case, if the array is empty the type for |
Performance Report✔️ no performance regression detected Full benchmark results
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## unstable #7533 +/- ##
=========================================
Coverage 50.14% 50.15%
=========================================
Files 603 603
Lines 40454 40442 -12
Branches 2226 2227 +1
=========================================
- Hits 20285 20282 -3
+ Misses 20129 20118 -11
- Partials 40 42 +2 🚀 New features to boost your workflow:
|
@@ -272,7 +272,7 @@ export function getBeaconPoolApi({ | |||
chain.syncCommitteeMessagePool.add(subnet, signature, indexInSubcommittee); | |||
|
|||
// Cheap de-duplication code to avoid using a Set. indexesInCommittee is always sorted | |||
if (subnets.length === 0 || subnets[subnets.length - 1] !== subnet) { | |||
if (subnets.length === 0 || subnets.at(-1) !== subnet) { |
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.
so -1
seems to be last item in the array, this is very confusing syntax
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.
Yes negative indexes are treated backwards. Which is also consistently used in other JS functions. e.g. arr.slice(-2);
returns last two items.
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.
arr.slice(-2); returns last two items.
yeah I know, somehow it makes more sense to me there, it's probably just a matter of getting used to it, if that's what needed to make array access more type safe I am all for it
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.
Yes .at
give type-safety compared to index access of the array. In case of under index or over index access the array returns undefined
but the type for index access is always without undefined. Which is resolved with .at
, so you must check if what you accessed is available or not.
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.
But that also need a careful review because if(!arr.at(-1))
such usages may fail if last value exists but is some falsy.
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.
generally lgtm
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.
seems fine to me, however we might wanna hold off merging stuff to unstable for now which is not critical to have in the next release.... just to make our lives easier in case there is a regression somewhere
Motivation
Keep the tooling updated.
Description
Steps to test or reproduce
Run all tests.
Please review commit by commit
For reviewers please review commit by commit.