Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TS 4.7 Instantiation Expressions for filterObject return type #806

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/containers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const asyncFilter = async <T>(arr: T[], predicate: (e: T) => Promise<bool
* @param filter An array of key strings that indicate which key-value pairs should be included or excluded.
* @return The resulting object devoid of key-value fields that did not match the key filter, or an empty object.
*/
export const filterObject = <V, T extends Record<string, V>>(obj: T, filter: string[]): T | Record<string, never> => {
export const filterObject = <V, T extends Record<string, V>>(obj: T, filter: string[]): ReturnType<typeof flattenObject<T>> => {
return Object.entries(flattenObject(obj))
.filter(([key]) => filter.includes(key))
.reduce((accumulator, [k, v]) => ({ ...accumulator, [k]: v }), {});
Expand Down