Repository navigation
Improve type check - #55
Conversation
There was a problem hiding this comment.
Pull request overview
This PR attempts to improve type checking in the getLastElementOf function but introduces a critical bug. The PR also includes a pnpm version upgrade and adds an ESLint import ordering rule to VS Code settings.
- The main code change adds a conditional check for
arr[index]before returning the element with its index - Updates pnpm package manager from version 10.18.2 to 10.24.0
- Adds
import/orderto the ESLint auto-fix rules in VS Code settings
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/universal/get-last-element-of.ts | Adds conditional check for array element existence, but uses incorrect truthy check that breaks for falsy values |
| package.json | Updates pnpm package manager to version 10.24.0 |
| .vscode/settings.json | Adds import/order to ESLint auto-fix rules for better import organization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (arr[index]) { | ||
| return { | ||
| el: arr[index], | ||
| index, | ||
| }; | ||
| } else { | ||
| return undefined; | ||
| } |
There was a problem hiding this comment.
This check introduces a bug. Using if (arr[index]) is a truthy check that will fail for valid falsy values like 0, false, "", or null. For example, getLastElementOf([1, 2, 0], {withIndex: true}) would incorrectly return undefined instead of {el: 0, index: 2}.
Since empty arrays are already handled at line 23-25, this additional check is unnecessary and should be removed. The original code was correct.
| if (arr[index]) { | |
| return { | |
| el: arr[index], | |
| index, | |
| }; | |
| } else { | |
| return undefined; | |
| } | |
| return { | |
| el: arr[index], | |
| index, | |
| }; |
No description provided.