Skip to content

Improve type check - #55

Merged
phanect merged 3 commits into
mainfrom
fix-type-check
Dec 1, 2025
Merged

phanect merged 3 commits into
mainfrom
fix-type-check

Conversation

@phanect

@phanect phanect commented Dec 1, 2025

Copy link
Copy Markdown
Owner

No description provided.

@phanect
phanect requested a review from Copilot December 1, 2025 23:52
@phanect phanect self-assigned this Dec 1, 2025
@phanect
phanect merged commit 1921fc3 into main Dec 1, 2025
13 checks passed
@phanect
phanect deleted the fix-type-check branch December 1, 2025 23:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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/order to 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.

Comment on lines +32 to +39
if (arr[index]) {
return {
el: arr[index],
index,
};
} else {
return undefined;
}

Copilot AI Dec 1, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
if (arr[index]) {
return {
el: arr[index],
index,
};
} else {
return undefined;
}
return {
el: arr[index],
index,
};

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants