Skip to content

Change offset and count checks to undefined#141

Open
tomcss wants to merge 1 commit into
RetroAchievements:mainfrom
tomcss:patch-1
Open

Change offset and count checks to undefined#141
tomcss wants to merge 1 commit into
RetroAchievements:mainfrom
tomcss:patch-1

Conversation

@tomcss

@tomcss tomcss commented Jul 13, 2026

Copy link
Copy Markdown

Since 0 can be a valid value (and is not the default value for count in this case) it is not appropriate to check count for truthy/falsy, but the check should be to see if it's defined instead.

Since 0 can be a valid value (and is not the default value for count in this case).
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The changed flow looks mergeable after handling null values from JavaScript callers.

  • Explicit zero values now reach URL serialization.
  • Omitted values remain excluded.

src/achievement/getAchievementUnlocks.ts

Reviews (1): Last reviewed commit: "Change offset and count checks to undefi..." | Re-trigger Greptile

Comment on lines +60 to 66
if (offset !== undefined) {
queryParams.o = offset;
}

if (count) {
if (count !== undefined) {
queryParams.c = count;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Null Values Become Query Parameters

JavaScript callers can pass null; this now serializes o=null or c=null instead of omitting the parameter. The API can reject the request.

Suggested change
if (offset !== undefined) {
queryParams.o = offset;
}
if (count) {
if (count !== undefined) {
queryParams.c = count;
}
if (offset != null) {
queryParams.o = offset;
}
if (count != null) {
queryParams.c = count;
}

Context Used: Be extremely concise in whatever you write on GitH... (source)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you sure? The args are optionally typed as foo?: number - not nullish.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right. With foo?: number, TypeScript types it as number | undefinednull is not assignable and can't be passed by a well-typed caller. The !== undefined check in the PR is the correct and precise guard here. My suggestion was overly defensive. Good catch.

Shall I remember this as a rule: "don't suggest != null guards for parameters typed as foo?: T!== undefined is the correct check since null isn't assignable to optional parameters"?

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, remember that as a rule.

Also - how many other files need to have !== undefined applied to them for count / offset params for consistency?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rule saved. View rule

Here's the full picture across the codebase:

5 files still using truthy checks (need fixing):

File Pattern
src/comment/getComments.ts if (offset) / if (count)
src/leaderboard/getLeaderboardEntries.ts if (payload?.offset) / if (payload?.count)
src/leaderboard/getUserGameLeaderboards.ts if (payload?.offset) / if (payload?.count)
src/user/getUserWantToPlayList.ts if (payload?.offset) / if (payload?.count)
src/feed/getRecentGameAwards.ts if (payload?.offset) / if (payload?.count)

2 files already correct (no action needed):

  • src/user/getUsersIFollow.ts — uses !== null && !== undefined (redundant but safe; could be simplified to just !== undefined)
  • src/user/getUsersFollowingMe.ts — same as above

So you have 5 files to update for consistency with this PR's fix.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cc @tomcss can we propagate this for consistency everywhere else mentioned above

@tomcss

tomcss commented Jul 13, 2026

Copy link
Copy Markdown
Author

I ran into this because I wanted to save bandwidth by retrieving the list with count 0 to see if there were any changes, so I could calculate the exact number of entries I had to download to complete my local data.

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