Skip to content

Commit 6542137

Browse files
authored
Merge pull request #41 from kakasoo/kakasoo/fix-deep-strict-unbrand
fix: add rest.length > 0 guard to deepStrictAssert
2 parents 301480e + 9aa5093 commit 6542137

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/functions/DeepStrictAssert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const deepStrictAssert =
3333
if (input instanceof Array) {
3434
const elements = input.map((element) => {
3535
if (first in element) {
36-
if (typeof element[first] === 'object' && element[first] !== null) {
36+
if (typeof element[first] === 'object' && element[first] !== null && rest.length > 0) {
3737
return { [first]: traverse(element[first], rest) };
3838
}
3939

@@ -46,7 +46,7 @@ export const deepStrictAssert =
4646
return elements;
4747
} else {
4848
if (first in input) {
49-
if (typeof input[first] === 'object' && input[first] !== null) {
49+
if (typeof input[first] === 'object' && input[first] !== null && rest.length > 0) {
5050
return { [first]: traverse(input[first], rest) };
5151
}
5252
return { [first]: input[first] };

test/features/DeepStrictAssert.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ export function test_functions_deepStrictAssert_accesses_nested_object_property(
105105
typia.assertEquals(deepStrictAssert(original)('user.name'));
106106
}
107107

108+
/**
109+
* Tests that deepStrictAssert can access a top-level key whose value is a plain object.
110+
*/
111+
export function test_functions_deepStrictAssert_accesses_top_level_object_property() {
112+
const original = typia.random<SimpleNested>();
113+
typia.assertEquals(deepStrictAssert(original)('user'));
114+
}
115+
108116
/**
109117
* Tests that deepStrictAssert throws when accessing a non-existent key.
110118
*/

0 commit comments

Comments
 (0)