Repository navigation
fix(oracles): use NoInfer in oracleProperty options for contextual typing - #195
schiller-manuel wants to merge 1 commit into
Conversation
…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>
|
Warning Review limit reachedYou'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. View limit details
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. |
|
Summary
GeneratedHistories.constructedandGeneratedHistories.fixedinNoInfer<...>soTHistoryis inferred strictly fromhistories.arbitrary(orenumerated) without interference fromfixed[].historyorconstructed[].build.THistory,TPlan, andTExpectedparameter/calibration positions onOraclePropertyOptions(label,resolve,model,reached,driver,check,calibrations,predict) inNoInfer<...>soTPlanis inferred solely fromresolve(defaulting toTHistory) andTExpectedsolely frommodel.constructedat the property level (NoInfer<ReadonlyArray<ConstructedHistory<THistory>>>) skipsconstructedduring TypeScript's inference passes, so context-sensitivebuildcallbacks (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.: Historyreturn annotations onconstructed[].buildinwithin-turns-oracle.property.test.ts,route-oracle.property.test.ts, andconfig-oracle.property.test.ts.packages/oracles/tests/property-inference.test-d.tscovering discriminated unions, fixed-length tuples,resolve, enumerated histories, explicit type arguments, and@ts-expect-errornegative checks.Remaining TypeScript limitation
In an unannotated
oracleProperty({ ... })call, a non-context-sensitiveconstructed[].buildcallback — specifically zero-parameterbuild: () => ({ ... })or an explicitly parameter-annotatedbuild: (base: History) => ({ ... })without a return annotation — is still evaluated and cached by TypeScript during pass 1 beforeTHistoryis 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 onoracleProperty<History, Expected>({ ... })avoids it.Validation
pnpm run build— passedpnpm run typecheck— passedpnpm run lint:check— passedpnpm run format:check— passedpnpm --filter @tanstack/oracles run test— 8 files / 117 tests passedpnpm --filter @tanstack/eslint-plugin-oracles run test— 15 files / 7,335 tests passedpnpm run test:publint— passed (All good!for both packages)pnpm run test:sherif— passed