Skip to content

Commit 48cbf95

Browse files
committed
fix: always returns object
1 parent 816008d commit 48cbf95

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isEmpty } from './isEmpty';
22

33
// Type of object shape
4-
export type Obj = { [key: string]: any };
4+
export type Object = { [key: string]: any };
55
// Type of ignored type
66
export type IgnoredTypes = null | undefined;
77
// Util to extract type from <T> value
@@ -15,7 +15,7 @@ export type OxReturn<ObjectType> = RemoveIgnoredKey<ObjectType>;
1515

1616
const toStr = Object.prototype.toString;
1717

18-
function cleanObject<T extends Obj>(obj: T, strict: boolean): OxReturn<T> {
18+
function cleanObject<T extends Object>(obj: T, strict: boolean): OxReturn<T> {
1919
let k: string;
2020
for (k in obj) {
2121
cleanProperty(k, obj[k], obj);
@@ -29,7 +29,7 @@ function cleanObject<T extends Obj>(obj: T, strict: boolean): OxReturn<T> {
2929
return null;
3030
}
3131

32-
function cleanProperty(key: string, value: any, ref: Obj) {
32+
function cleanProperty(key: string, value: any, ref: Object) {
3333
if (!shouldCleanProperty(value)) {
3434
delete ref[key];
3535
return;
@@ -60,12 +60,18 @@ function cleanObject<T extends Obj>(obj: T, strict: boolean): OxReturn<T> {
6060
export default function ox<T, U extends boolean>(
6161
obj?: T,
6262
strict?: U
63-
): T extends Obj ? (U extends false ? T : OxReturn<T>) : T {
63+
): T extends boolean
64+
? Object
65+
: T extends Object
66+
? U extends false
67+
? T
68+
: OxReturn<T>
69+
: T {
6470
if (typeof strict === 'undefined') {
6571
strict = true as U;
6672
}
6773
if (!obj || typeof obj === 'boolean') return {} as any;
68-
return cleanObject(obj as Obj, strict as boolean) ?? ({} as any);
74+
return cleanObject(obj as Object, strict as boolean) ?? ({} as any);
6975
}
7076

7177
export { isEmpty };

0 commit comments

Comments
 (0)