Skip to content

fix(tanstack-store): accept an explicit undefined comparator - #952

Merged
trueadm merged 1 commit into
mainfrom
fix/tanstack-store-optional-compare
Sep 5, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/tanstack-store-optional-compare

Conversation

@WebEferen

@WebEferen WebEferen commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@octanejs/tanstack-store publishes src/, so the consumer's tsc compiles it with the consumer's flags. Under exactOptionalPropertyTypes the package does not build at all:

packages/tanstack-store/src/useStore.ts(49,22): error TS2379: Argument of type
'{ compare: ((a: TSelected, b: TSelected) => boolean) | undefined; }' is not
assignable to parameter of type 'UseSelectorOptions<TSelected>' with
'exactOptionalPropertyTypes: true'.

useStore normalises its variadic arguments and always passes the compare key, which may hold undefined. UseSelectorOptions.compare was declared without undefined, so the internal bridge fails, and so does any consumer forwarding their own optional comparator ({ compare: maybeCompare }).

Declaring compare?: Compare | undefined accepts both. No runtime change: useSelector already read the option as options?.compare ?? defaultCompare, so an absent key and an explicit undefined behaved identically before and after.

Found while building an Octane app with exactOptionalPropertyTypes on. It was shipping a pnpm patch against the published tarball; this is the same fix upstream.

Validation

Repo-wide pnpm typecheck and pnpm test were not run (unchanged elsewhere; the diff is one type declaration).

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted: tsrx-tsc -p packages/tanstack-store/tsconfig.json, tsrx-tsc -p packages/tanstack-store/typetests/tsconfig.json, vitest run --project "*tanstack-store*" (9 files, 51 tests)
  • reproduction: scripts/consumer-tsconfigs/tanstack-store.json plus exactOptionalPropertyTypes and noUncheckedIndexedAccess reports the error above before the change and nothing from this package after it

Risk / follow-ups

No gate covers this. scripts/consumer-tsconfigs/base.json mirrors what octane init scaffolds, which leaves both flags off, and turning them on in a package tsconfig pulls packages/octane/src into the program, where the same classes of error exist in bulk. A real consumer never sees those, because octane publishes dist with declarations behind skipLibCheck, while every @octanejs/* binding publishes source. The header of scripts/generate-consumer-tsconfigs.mjs already records that debt against #721; widening those projects is worth doing once core is clean.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Low Risk
Type-only widening for optional properties; no runtime or behavioral change.

Overview
Fixes TypeScript compile failures when consumers build @octanejs/tanstack-store with exactOptionalPropertyTypes. Because the package ships source, the app’s compiler type-checks useStore → useSelector and any forwarded { compare: maybeCompare } objects.

UseSelectorOptions.compare is now typed as an optional property that also allows undefined (compare?: Compare | undefined), with a short comment explaining why. useStore can keep passing { compare } when the third argument is omitted, and callers can forward optional comparators without assignment errors.

Runtime behavior is unchanged — useSelector still resolves the comparator via options?.compare ?? defaultCompare.

Reviewed by Cursor Bugbot for commit 6429425. Bugbot is set up for automated code reviews on this repo. Configure here.

`useStore` normalises its variadic arguments into `{ compare }`, so the key is
always present and may hold `undefined`. `UseSelectorOptions.compare` was
declared without `undefined`, which is a type error under
`exactOptionalPropertyTypes`. The package publishes `src/`, so that is the
consumer's compiler flag, not ours: an application with the flag on could not
build the package at all, and could not forward its own optional comparator
either.

Runtime behavior is unchanged; `useSelector` already read the option as
`options?.compare ?? defaultCompare`.
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 4, 2026
@WebEferen
WebEferen marked this pull request as ready for review September 4, 2026 16:27
@WebEferen
WebEferen marked this pull request as draft September 4, 2026 16:33
@trueadm
trueadm marked this pull request as ready for review September 5, 2026 17:26
@trueadm
trueadm merged commit 1ee2773 into main Sep 5, 2026
85 of 94 checks passed
@trueadm
trueadm deleted the fix/tanstack-store-optional-compare branch September 5, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants