Skip to content

[FEAT] Add deepStrictOmit runtime function #52

@kakasoo

Description

@kakasoo

Feature Request

  • Extensions of existing features
  • Propose a type that didn't exist before

Type Expectation

The runtime implementation for deepStrictPick exists, but its inverse operation deepStrictOmit has no runtime implementation. Since Pick and Omit are commonly used as a pair, a deepStrictOmit runtime function is needed for API completeness.

Example Type

const input = {
  a: 1,
  b: { c: 2, d: 3 },
  e: [{ f: 4, g: 5 }],
};

const result = deepStrictOmit(input, 'b.c');
// result: { a: 1, b: { d: 3 }, e: [{ f: 4, g: 5 }] }
// typeof result: DeepStrictOmit<typeof input, 'b.c'>

const result2 = deepStrictOmit(input, 'e[*].f');
// result2: { a: 1, b: { c: 2, d: 3 }, e: [{ g: 5 }] }

Proposed Solution

  1. Create src/functions/DeepStrictOmit.ts
  2. Signature: deepStrictOmit<T extends object, K extends DeepStrictObjectKeys<T>>(input: T, key: K): DeepStrictOmit<T, K>
  3. Reference the traverse pattern from deepStrictPick, but invert the logic (only remove specified keys)
  4. Add re-export to src/functions/index.ts
  5. Use [*] pattern for removing keys from each element during array traversal

Use Case

  • Remove sensitive fields from API responses (password, secret, etc.)
  • Strip unnecessary nested fields before sending to client
  • Provide a symmetric API alongside deepStrictPick

Test Requirements

All changes must include the following tests:

  1. Backward Compatibility

    • All existing tests must pass
  2. Feature Verification

    • Top-level key omit (deepStrictOmit(obj, 'a'))
    • Nested key omit (deepStrictOmit(obj, 'a.b'))
    • Array inner key omit (deepStrictOmit(obj, 'items[*].id'))
    • Non-existent keys produce a type error (compile time)
    • Return type matches DeepStrictOmit<T, K>
  3. Complex Type Stability

    • 3+ levels of nested omit
    • 2D array inner omit (items[*].sub[*].value)
    • Omit from objects with Date properties (Date preserved)
    • Omit from objects with branded types
    • Omitting all keys results in an empty object
    • Empty array input
    • Immutability check (input is not mutated)

How to verify:

npm run build:test && npm run test
npm run prettier

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions