diff --git a/src/functions/DeepStrictObjectKeys.ts b/src/functions/DeepStrictObjectKeys.ts index 0cff082..ec53641 100644 --- a/src/functions/DeepStrictObjectKeys.ts +++ b/src/functions/DeepStrictObjectKeys.ts @@ -12,7 +12,6 @@ export function deepStrictObjectKeys< new Set( Object.entries(target).flatMap(([key, value]) => { if (target instanceof Array) { - console.log('value: ', value); return deepStrictObjectKeys(value, joiner).map((el) => `${joiner.array}.${el}`); } else if (target !== null && typeof target === 'object') { return deepStrictObjectKeys(value, joiner).flatMap((el) => `${joiner.object}.${el}`); diff --git a/src/types/DeepStrictObjectKeys.ts b/src/types/DeepStrictObjectKeys.ts index 2ffc778..d868ef0 100644 --- a/src/types/DeepStrictObjectKeys.ts +++ b/src/types/DeepStrictObjectKeys.ts @@ -4,8 +4,6 @@ import type { IsAny } from './IsAny'; import type { IsUnion } from './IsUnion'; import type { ValueType } from './ValueType'; -type a = DeepStrictObjectKeys.Infer<{ a: Date }>; - namespace DeepStrictObjectKeys { export type Infer< Target extends object, @@ -69,5 +67,9 @@ export type DeepStrictObjectKeys< DeepStrictUnbrand extends Array ? Element extends object ? `${Joiner['array']}.${DeepStrictObjectKeys}` - : `${Joiner['array']}.${keyof Element extends string ? keyof Element : never}` - : DeepStrictObjectKeys.Infer, Joiner, IsSafe>; + : `${Joiner['array']}` + : DeepStrictUnbrand extends readonly (infer Element)[] // TODO: support tuple types + ? Element extends object + ? `${Joiner['array']}.${DeepStrictObjectKeys}` + : `${Joiner['array']}` + : DeepStrictObjectKeys.Infer, Joiner, IsSafe>; diff --git a/test/types/DeepStrictObjectKeys.ts b/test/types/DeepStrictObjectKeys.ts index af476d1..eebcb68 100644 --- a/test/types/DeepStrictObjectKeys.ts +++ b/test/types/DeepStrictObjectKeys.ts @@ -3,6 +3,34 @@ import test, { describe } from 'node:test'; import typia, { tags } from 'typia'; import { DeepStrictObjectKeys, Equal } from '../../src'; +describe('empty array', () => { + test('normal: isNotSafe', () => { + type Question = DeepStrictObjectKeys< + [], + { + array: '[*]'; + object: '.'; + }, + false + >; + type Answer = Equal; + ok(typia.random()); + }); + + test('normal: isNotSafe', () => { + type Question = DeepStrictObjectKeys< + [], + { + array: '[*]'; + object: '.'; + }, + true + >; + type Answer = Equal; + ok(typia.random()); + }); +}); + describe('Date props', () => { test('normal: isNotSafe', () => { type Question = DeepStrictObjectKeys< @@ -578,3 +606,59 @@ describe('a key in a two-dimensional array', () => { ok(typia.random()); }); }); + +describe('readonly empty array. (tuple)', () => { + test('normal: isNotSafe', () => { + type Question = DeepStrictObjectKeys< + readonly [], + { + array: '[*]'; + object: '.'; + }, + false + >; + type Answer = Equal; + ok(typia.random()); + }); + + test('normal: isSafe', () => { + type Question = DeepStrictObjectKeys< + readonly [], + { + array: '[*]'; + object: '.'; + }, + true + >; + type Answer = Equal; + ok(typia.random()); + }); +}); + +describe('readonly not empty array. (tuple)', () => { + test('normal: isNotSafe', () => { + type Question = DeepStrictObjectKeys< + readonly [1], + { + array: '[*]'; + object: '.'; + }, + false + >; + type Answer = Equal; + ok(typia.random()); + }); + + test('normal: isSafe', () => { + type Question = DeepStrictObjectKeys< + readonly [1], + { + array: '[*]'; + object: '.'; + }, + true + >; + type Answer = Equal; + ok(typia.random()); + }); +});