Skip to content

Commit 841889f

Browse files
fix(utils): accept null as default option in applyDefault (typescript-eslint#6724)
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
1 parent 1404796 commit 841889f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/utils/src/eslint-utils/deepMerge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type ObjectLike<T = unknown> = Record<string, T>;
66
* @returns `true` if obj is an object
77
*/
88
function isObjectNotArray<T extends ObjectLike>(obj: unknown): obj is T {
9-
return typeof obj === 'object' && !Array.isArray(obj);
9+
return typeof obj === 'object' && obj != null && !Array.isArray(obj);
1010
}
1111

1212
/**

packages/utils/tests/eslint-utils/applyDefault.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,18 @@ describe('applyDefault', () => {
5959
expect(result).not.toBe(defaults);
6060
expect(result).not.toBe(user);
6161
});
62+
63+
it('should work when default option is null', () => {
64+
const defaults: unknown[] = [null];
65+
const user: unknown[] = [
66+
{
67+
prop: 'setting1',
68+
other: 'other',
69+
},
70+
];
71+
const result = ESLintUtils.applyDefault(defaults, user);
72+
expect(result).toStrictEqual(user);
73+
expect(result).not.toBe(defaults);
74+
expect(result).not.toBe(user);
75+
});
6276
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy