Skip to content

Commit

Permalink
🏷️ Fix typing of strictObjectAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
horaklukas committed Feb 24, 2022
1 parent b1e7fc4 commit 5c03f21
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/utilities/strictObjectAccess/strictObjectAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ const handler = {
};

/**
If there is an attempt to read an undefined property,
an error is thrown.
@param {object} target
@param {boolean} enabled
@return {object}
*/
export default function strictObjectAccess(
target: any = {},
* If there is an attempt to read an undefined property, an error is thrown.
*/
export default function strictObjectAccess<T extends object>(
target: T = {} as T,
enabled: boolean = typeof process === 'object' ? process.env.NODE_ENV === 'development' : true,
) {
): T {
// omit the functionality outside of development env.
return enabled ? new Proxy(target, handler) : target;
return enabled ? new Proxy<T>(target, handler) : target;
}

0 comments on commit 5c03f21

Please sign in to comment.