Skip to content

Instantly share code, notes, and snippets.

@frivolta
Last active January 10, 2020 13:32
Show Gist options
  • Save frivolta/4b45dd16c9cc33f98cab7bba8502fe6c to your computer and use it in GitHub Desktop.
Save frivolta/4b45dd16c9cc33f98cab7bba8502fe6c to your computer and use it in GitHub Desktop.
// Add a new generic type P
const filterArrayByValue = <T, P extends keyof T>(
items: T[],
propertyName: P,
valueToFilter: string
): T[] => {
return items.filter(item =>item[propertyName] === valueToFilter);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment