kakasoo / kakasoo/DeepStrictTypes

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

Open
#50 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
64
Forks
2
PR merge metrics
No merged PRs in 30d

Description

# Feature Request

- [x] 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**

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

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

// optional + nesting
type Input3 = { a?: { b?: { c: number } } };
type Q3 = DeepStrictPick;
type A3 = Equal;
```

**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:**
```bash
npm run build:test && npm run test
npm run prettier
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.