Skip to content

Remove AtLeastOne/AtMostOne type constraints for simpler type inference#10

Open
konard wants to merge 3 commits intotool2agent:masterfrom
konard:issue-8-51b77baef2bd
Open

Remove AtLeastOne/AtMostOne type constraints for simpler type inference#10
konard wants to merge 3 commits intotool2agent:masterfrom
konard:issue-8-51b77baef2bd

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Dec 27, 2025

Summary

This PR simplifies the type machinery by removing AtLeastOne and AtMostOne utility types, as requested in #8. The key changes are:

  • Removed AtLeastOne/AtMostOne utility types from types.ts - these complex conditional types were hurting TypeScript's ability to infer types correctly
  • Made previously constrained fields optional at the type level (e.g., validationResults, problems, allowedValues, suggestedValues)
  • Preserved the conditional type for value/inline object branching in ToolCallSuccess - this was explicitly requested to stay
  • Runtime validation via Zod schemas in @tool2agent/schemas still enforces the AtLeastOne/AtMostOne constraints at runtime

Before vs After

Before:

// Complex utility types that hurt inference
export type AtLeastOne<T, K extends keyof T = keyof T> = Omit<T, K> &
  { [P in K]: Required<Pick<T, P>> & Partial<Omit<T, P>>; }[K];

export type AtMostOne<T, K extends keyof T = keyof T> = Omit<T, K> &
  ( | { [P in K]?: never }
    | { [P in K]: Required<Pick<T, P>> & Partial<Record<Exclude<K, P>, never>> }[K] );

// Used in types like:
export type RecordFailureFeedback<T> = AtLeastOne<{
  validationResults: AtLeastOne<{...}>;
  problems: NonEmptyArray<string>;
}>;

After:

// Simple optional fields - constraints enforced at runtime
export type RecordFailureFeedback<T> = {
  validationResults?: {...};
  problems?: NonEmptyArray<string>;
};

Files Changed

  • packages/types/src/types.ts - Removed AtLeastOne/AtMostOne exports
  • packages/types/src/tool2agent.ts - Simplified types using optional fields
  • packages/schemas/src/schema-tools.ts - Removed type imports (runtime validation unchanged)
  • packages/types/test-d/*.ts - Updated type tests for new behavior
  • packages/schemas/test/schemas.test.ts - Updated test expectations

Test plan

  • Build passes (pnpm build)
  • Lint passes (pnpm lint)
  • Format check passes (pnpm format:check)
  • Type tests pass (packages/types/test:types)
  • Schema tests pass (packages/schemas/test)
  • AI package tests pass (unit and types)

Note: Two pre-existing runtime test failures exist in the AI package (missing API key and a JSON.stringify edge case) - these are unrelated to this PR.

Fixes #8

🤖 Generated with Claude Code

konard and others added 2 commits December 27, 2025 11:48
Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: tool2agent#8
This simplifies the type machinery by:
- Removing AtLeastOne and AtMostOne utility types from types.ts
- Making the constrained fields optional at the type level
- Keeping runtime validation via Zod schemas in @tool2agent/schemas
- Preserving the ToolCallSuccess conditional type for value/inline object branching

The AtLeastOne/AtMostOne type constraints were complex and hurt TypeScript's
ability to infer types correctly. By removing them from the type system and
relying on runtime Zod schema validation instead, we get simpler types that
are easier to work with while maintaining the same runtime safety guarantees.

Fixes tool2agent#8

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] consider simplifying type machinery to improve type inference Remove AtLeastOne/AtMostOne type constraints for simpler type inference Dec 27, 2025
@konard konard marked this pull request as ready for review December 27, 2025 10:58
@konard
Copy link
Copy Markdown
Author

konard commented Dec 27, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.088888 USD
  • Calculated by Anthropic: $3.201868 USD
  • Difference: $-1.887020 (-37.08%)
    📎 Log file uploaded as GitHub Gist (788KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

consider simplifying type machinery to improve type inference

1 participant