Skip to content

Commit 6c38cf2

Browse files
authored
improve: ObjectFilter
1 parent f32aed0 commit 6c38cf2

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

source/filter.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ type FilterOptions = {
2121
*/
2222

2323
strict?: boolean;
24-
}
24+
};
2525

2626
type DefaultFilterOptions = {
2727
strict: false;
28-
}
28+
};
2929

3030
/**
3131
Shorhand for `ApplyDefaultOptions<...>`

source/object-filter.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {FilterOptions, FilterType, ApplyFilterOptions} from './filter.d.ts'
22
import type {UnknownRecord} from './unknown-record.d.ts';
33
import type {CleanEmpty} from './internal/array.d.ts';
44
import type {Simplify} from './simplify.d.ts';
5+
import { IsAny } from './is-any.js';
56

67
/**
78
Filters properties from an object where the property value matches the given type.
@@ -12,16 +13,17 @@ Strict controls whether strict or loose type comparison is used (defaults to loo
1213
*/
1314
type ObjectFilter<
1415
Object_ extends UnknownRecord, Type,
15-
Options extends FilterOptions = {}
16-
> = _ObjectFilter<Object_, Type, ApplyFilterOptions<Options>['strict']>
16+
Options extends FilterOptions = {},
17+
> = IsAny<Object_> extends true ? {}
18+
: CleanEmpty<_ObjectFilter<Object_, Type, ApplyFilterOptions<Options>['strict']>>;
1719

1820
export type _ObjectFilter<
1921
Object_ extends UnknownRecord, Type,
2022
Strict extends boolean = false,
21-
> = CleanEmpty<Simplify<{
23+
> = Simplify<{
2224
[Key in keyof Object_ as
2325
FilterType<Object_[Key], Type, Strict> extends true
2426
? Key
2527
: never
2628
]: Object_[Key]
27-
}>>;
29+
}>;

0 commit comments

Comments
 (0)