Skip to content

Commit 7f77fc0

Browse files
committed
fix: isObject should return false for functions
The `isObject` function incorrectly returned `true` for function values because it checked `typeof value === 'function'` in addition to `typeof value === 'object'`. The README documentation explicitly states that functions should return false, but the implementation contradicted this. Fixes #2515
1 parent 2e1a5c2 commit 7f77fc0

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/decorator/typechecker/IsObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const IS_OBJECT = 'isObject';
88
* Returns false if the value is not an object.
99
*/
1010
export function isObject<T = object>(value: unknown): value is T {
11-
return value != null && (typeof value === 'object' || typeof value === 'function') && !Array.isArray(value);
11+
return value != null && typeof value === 'object' && !Array.isArray(value);
1212
}
1313

1414
/**

test/functional/validation-functions-and-decorators.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,6 +3166,10 @@ describe('IsObject', () => {
31663166
'[]',
31673167
[],
31683168
[{ key: 'value' }],
3169+
() => 'function',
3170+
function namedFn() {
3171+
return 'named function';
3172+
},
31693173
];
31703174

31713175
class MyClass {

0 commit comments

Comments
 (0)