Skip to content

[TEST] Add edge case tests for readonly and optional modifiers #50

@kakasoo

Description

@kakasoo

Feature Request

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

Type Expectation

Core types like DeepStrictPick, DeepStrictOmit, DeepStrictMerge, and DeepDateToString lack explicit tests for readonly properties and optional(?:) properties. Since modifier preservation is critical to type safety, explicit tests are needed to prevent regressions.

Example Type

// optional preservation test
type Input = { a?: number; b: string; c?: { d: number } };
type Q1 = DeepStrictPick<Input, "a">;
type A1 = Equal<Q1, { a?: number }>;  // verify optional is preserved

// readonly property preservation test
type Input2 = { readonly a: number; b: string };
type Q2 = DeepStrictPick<Input2, "a">;
type A2 = Equal<Q2, { readonly a: number }>;  // verify readonly is preserved

// optional + nesting
type Input3 = { a?: { b?: { c: number } } };
type Q3 = DeepStrictPick<Input3, "a.b.c">;
type A3 = Equal<Q3, { a?: { b?: { c: number } } }>;

Proposed Solution

Add edge case tests to existing test files (DeepStrictPick.ts, DeepStrictOmit.ts, DeepStrictMerge.ts, DeepDateToString.ts).

Test Requirements

All changes must include the following tests:

  1. Backward Compatibility

    • All existing tests must pass
    • Add tests to verify that existing type behavior remains unchanged
  2. Feature Verification

    • optional properties are preserved after pick/omit
    • readonly properties are preserved after pick/omit
    • How optional/readonly from both sides are handled during merge
  3. Complex Type Stability

    • { a?: readonly { b?: number }[] } (optional + readonly + array)
    • { readonly a?: { readonly b: Date } } (readonly + optional + Date)
    • readonly [{ a?: 1 }, { b: 2 }] (readonly tuple + optional)
    • Branded type + optional ({ a?: string & MinLength<1> })
    • Union + optional ({ a?: string | null })
    • 3-level nested optional ({ a?: { b?: { c?: number } } })

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