kakasoo / kakasoo/DeepStrictTypes

deepStrictObjectKeys runtime function recurses into Date objects

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

Description

## Bug

The runtime function `deepStrictObjectKeys` recurses into `Date` objects, producing keys like `"createdAt.toISOString"`, `"createdAt.getTime"`, etc. The type-level `DeepStrictObjectKeys` correctly treats `Date` as a leaf (via the `ValueType` check), so this is a type/runtime mismatch.

### Reproduction

```ts
const obj = { createdAt: new Date() };
const keys = deepStrictObjectKeys(obj);
// Type says: ("createdAt")[]
// Runtime produces: ["createdAt", "createdAt.toISOString", "createdAt.getTime", ...]
```

### Root Cause

`src/functions/DeepStrictObjectKeys.ts` line 68:

```ts
if (typeof value === 'object' && value !== null) {
const children = deepStrictObjectKeys(value).map((el) => `${key}.${el}`);
response.push(...children);
}
```

`typeof new Date() === 'object'` is `true`, so Date is recursed into. The type-level counterpart uses `ValueType` (which includes `Date`) to stop recursion, but the runtime function has no equivalent guard.

### Suggested Fix

Add `&& !(value instanceof Date)` to the condition:

```ts
if (typeof value === 'object' && value !== null && !(value instanceof Date)) {
```

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.