Skip to content

Commit

Permalink
[#186] add type ValueKeyIteratee, ValueKeyIterateeTypeGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
yujeong-jeon committed Jan 8, 2025
1 parent ae16e24 commit dcc2faa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/internal/baseIteratee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ObjectIterateeCustom,
ObjectIterator,
PropertyName,
ValueKeyIteratee,
} from './baseIteratee.type'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -52,9 +53,8 @@ function isMatch(element: unknown, source: unknown): boolean {

export function baseIteratee<T, TResult>(iteratee: ObjectIterateeCustom<T, TResult>): ObjectIterator<T, TResult>
export function baseIteratee<T, TResult>(iteratee: ListIterateeCustom<T, TResult>): ListIterator<T, TResult>
export function baseIteratee<T, TResult>(
iteratee: ListIterateeCustom<T, TResult> | ObjectIterateeCustom<T, TResult>,
): ListIterator<T, TResult> | ObjectIterator<T, TResult> {
export function baseIteratee<T, TResult>(iteratee: ValueKeyIteratee<T>): ObjectIterator<T, TResult>
export function baseIteratee<T, TResult>(iteratee: unknown) {
if (iteratee == null) {
return function (element: T) {
return element as unknown as TResult
Expand Down
2 changes: 2 additions & 0 deletions src/internal/baseIteratee.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type ListIterateeCustom<T, TResult> = ListIterator<T, TResult> | Iteratee
export type ListIteratorTypeGuard<T, S extends T> = (value: T, index: number, collection: List<T>) => value is S

export type ValueIteratee<T> = ((value: T) => unknown) | IterateeShorthand<T>
export type ValueKeyIteratee<T> = ((value: T, key: string) => unknown) | IterateeShorthand<T>
export type ValueKeyIterateeTypeGuard<T, S extends T> = (value: T, key: string) => value is S

export type ObjectIterator<T, TResult> = (value: T[keyof T], key: string, collection: T) => TResult
export type ObjectIteratee<TObject> = ObjectIterator<TObject, unknown> | IterateeShorthand<TObject[keyof TObject]>
Expand Down

0 comments on commit dcc2faa

Please sign in to comment.