Skip to content

Commit

Permalink
feat(type): add CallbackPayload and ForEachCallback types.
Browse files Browse the repository at this point in the history
  • Loading branch information
sciborrudnicki committed Sep 20, 2021
1 parent e09a84f commit 98a2722
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/type/callback-payload.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Experimental shape for a generic type variable `Payload`.
*/
export type CallbackPayload<Payload = object> = {
/**
* An optional action of a `string` type that describes the cause of performed callback.
*/
action?: string;

/**
* An optional name of the function or method of a `string` type that performed callback.
*/
name?: string;

/**
* An optional name of the parameter of a `string` type to which performed callback relates.
*/
param?: string;

} & Payload;
16 changes: 16 additions & 0 deletions src/type/foreach-callback.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Represents a callback function of `forEach()` method which is executed once for each element.
* @param result The result of the check of a `boolean` type.
* @param value The value that has been checked of a generic type variable `Value`.
* @param index An optional `number` of checked `array` element.
* @param array An optional `array` of `any` type that each element is checked.
* @param payload An optional `object` of a generic type variable `Payload` to provide more data.
* @returns The return value is void.
*/
export type ForEachCallback<Value = any, Payload = object> = (
result: boolean,
value: Value,
index?: number,
array?: any[],
payload?: Payload
) => void;

0 comments on commit 98a2722

Please sign in to comment.