Skip to content

Commit

Permalink
Use generic for target type
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Feb 21, 2024
1 parent 7f786b6 commit 318509e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/support/src/objects/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { isKeySafe } from "@aedart/support/reflections";
*
* **Note**: _Properties that are [unsafe]{@link import('@aedart/support/reflections').isKeyUnsafe} are always disregarded!_
*
* @template T = object
*
* @param {object} target
* @param {object} source
* @param {PropertyKey | PropertyKey[]} [keys='*'] If wildcard (`*`) given, then all properties from the `source` are selected.
Expand All @@ -20,7 +22,12 @@ import { isKeySafe } from "@aedart/support/reflections";
* @throws {TypeError} If a key does not exist in `target` (_when `safe = true`_).
* Or, if key does not exist in `source` (_regardless of `safe` flag_).
*/
export function populate(target: object, source: object, keys: PropertyKey|PropertyKey[] = '*', safe: boolean = true): object
export function populate<T extends object = object>(
target: T,
source: object,
keys: PropertyKey|PropertyKey[] = '*',
safe: boolean = true
): T
{
if (keys === '*') {
keys = Reflect.ownKeys(source);
Expand Down

0 comments on commit 318509e

Please sign in to comment.