Skip to content

fix(oracles): use NoInfer in oracleProperty options for contextual typing - #195

Open
schiller-manuel wants to merge 1 commit into
mainfrom
fix/oracle-property-noinfer
Open

schiller-manuel wants to merge 1 commit into
mainfrom
fix/oracle-property-noinfer

Conversation

@schiller-manuel

Copy link
Copy Markdown

Summary

  • Wrap GeneratedHistories.constructed and GeneratedHistories.fixed in NoInfer<...> so THistory is inferred strictly from histories.arbitrary (or enumerated) without interference from fixed[].history or constructed[].build.
  • Wrap THistory, TPlan, and TExpected parameter/calibration positions on OraclePropertyOptions (label, resolve, model, reached, driver, check, calibrations, predict) in NoInfer<...> so TPlan is inferred solely from resolve (defaulting to THistory) and TExpected solely from model.
  • Wrapping constructed at the property level (NoInfer<ReadonlyArray<ConstructedHistory<THistory>>>) skips constructed during TypeScript's inference passes, so context-sensitive build callbacks (e.g. build: (base) => ({ ...base, mode: 'a', mask: [true, false] }), (_base) => ..., destructured params, and block bodies) now receive full contextual parameter and return typing for discriminated unions and fixed-length tuples — with zero runtime or export-surface changes.
  • Removed the now-unnecessary : History return annotations on constructed[].build in within-turns-oracle.property.test.ts, route-oracle.property.test.ts, and config-oracle.property.test.ts.
  • Added compile-time regression tests in packages/oracles/tests/property-inference.test-d.ts covering discriminated unions, fixed-length tuples, resolve, enumerated histories, explicit type arguments, and @ts-expect-error negative checks.

Remaining TypeScript limitation

In an unannotated oracleProperty({ ... }) call, a non-context-sensitive constructed[].build callback — specifically zero-parameter build: () => ({ ... }) or an explicitly parameter-annotated build: (base: History) => ({ ... }) without a return annotation — is still evaluated and cached by TypeScript during pass 1 before THistory is resolved, so literal/tuple widening can still occur there. Using an unannotated parameter ((base) => ... or (_base) => ...), annotating the return type, or providing explicit type arguments on oracleProperty<History, Expected>({ ... }) avoids it.

Validation

  • pnpm run build — passed
  • pnpm run typecheck — passed
  • pnpm run lint:check — passed
  • pnpm run format:check — passed
  • pnpm --filter @tanstack/oracles run test — 8 files / 117 tests passed
  • pnpm --filter @tanstack/eslint-plugin-oracles run test — 15 files / 7,335 tests passed
  • pnpm run test:publint — passed (All good! for both packages)
  • pnpm run test:sherif — passed

…ping

Wrap non-inferring history, plan, and expected positions on
GeneratedHistories and OraclePropertyOptions in TypeScript's native
NoInfer<T> so THistory is inferred solely from histories.arbitrary or
enumerated histories, TPlan solely from resolve (defaulting to
THistory), and TExpected solely from model.

Wrapping GeneratedHistories.constructed and GeneratedHistories.fixed at
the array property level prevents TypeScript from evaluating
context-sensitive build callbacks during inference passes, so unannotated
build: (base) => ({ ... }) callbacks and fixed[].history literals receive
contextual typing for discriminated unions and fixed-length tuples.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: df973b8a-1482-4d88-850c-be7e144a9b22
Commits

Reviewing files that changed from the base of the PR and between 7b6bae1 and 6bd6a94.

Files selected for processing: 5

  • packages/oracles/src/oracle-property.ts
  • packages/oracles/tests/config-oracle.property.test.ts
  • packages/oracles/tests/property-inference.test-d.ts
  • packages/oracles/tests/route-oracle.property.test.ts
  • packages/oracles/tests/within-turns-oracle.property.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@changeset-bot

changeset-bot Bot commented Nov 23, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6bd6a94

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

1 participant