Skip to content

Add type utilities: KeyOf, Template, DeepPartial, Partial, Required, Pick, Omit#17

Merged
AliiiBenn merged 3 commits intomainfrom
add-partial-required
Mar 5, 2026
Merged

Add type utilities: KeyOf, Template, DeepPartial, Partial, Required, Pick, Omit#17
AliiiBenn merged 3 commits intomainfrom
add-partial-required

Conversation

@AliiiBenn
Copy link
Member

@AliiiBenn AliiiBenn commented Mar 5, 2026

Summary

Add comprehensive type utilities for type manipulation:

  • KeyOf[T]: Returns all member names as a tuple of Literal types
  • Template[*Parts]: Template literal string builder
  • DeepPartial[T]: Make all fields recursively optional
  • Partial[T]: Make all fields optional (non-recursive)
  • Required[T]: Remove Optional from all fields
  • Pick[T, K]: Pick specific fields from a type
  • Omit[T, K]: Omit specific fields from a type

Examples

KeyOf[T]

class User:
    name: str
    age: int

# Returns tuple[Literal["name"], Literal["age"]]
type Keys = KeyOf[User]

Template[*Parts]

Resource = Literal["users"]
# Returns Literal["api/v1/users"]
type Route = Template["api/v1/", Resource]

DeepPartial[T]

class User:
    name: str
    address: Address

# All fields become optional recursively
type PartialUser = DeepPartial[User]
# Result: address.street: str | None (nested optional)

Partial[T]

class User:
    name: str
    age: int

# All fields become optional (non-recursive)
type PartialUser = Partial[User]
# Result: name: str | None, age: int | None

Required[T]

class User:
    name: str | None
    age: int | None

# Remove Optional from all fields
type RequiredUser = Required[User]
# Result: name: str, age: int

Pick[T, K]

class User:
    name: str
    email: str
    password: str

# Pick specific fields
type PublicUser = Pick[User, tuple["name", "email"]]
# Result: name: str, email: str (password excluded)

Omit[T, K]

class User:
    name: str
    email: str
    password: str

# Omit specific fields
type SafeUser = Omit[User, tuple["password"]]
# Result: name: str, email: str (password excluded)

Test Plan

  • KeyOf tests (6 tests)
  • Template tests (5 tests)
  • DeepPartial tests (6 tests)
  • Partial tests (6 tests)
  • Required tests (6 tests)
  • Pick tests (6 tests)
  • Omit tests (7 tests)

All 155 tests pass.

🤖 Generated with Claude Code

…Pick, Omit

Add the following type utilities:
- KeyOf[T]: Returns all member names as a tuple of Literal types
- Template[*Parts]: Template literal string builder
- DeepPartial[T]: Make all fields recursively optional
- Partial[T]: Make all fields optional (non-recursive)
- Required[T]: Remove Optional from all fields
- Pick[T, K]: Pick specific fields from a type
- Omit[T, K]: Omit specific fields from a type

Add comprehensive tests for all new types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@AliiiBenn AliiiBenn force-pushed the add-partial-required branch from 8a87ffb to fba80da Compare March 5, 2026 12:12
AliiiBenn and others added 2 commits March 5, 2026 13:36
- Add more complex tests for KeyOf (order preservation)
- Add more tests for DeepPartial (optional fields, type preservation)
- Add more tests for Partial (union types)
- Add more tests for Required (multiple optionals)
- Add more tests for Pick (single-element tuples)
- Add more tests for Omit (single-element tuples, all fields omitted)
- Add Template tests (basic functionality verification)

Total: 155 tests passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Update version from 0.1.2 to 0.2.0
- Add CHANGELOG.md with release notes
- Add examples for new type utilities in README.md

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@AliiiBenn AliiiBenn merged commit 9345131 into main Mar 5, 2026
3 checks passed
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