Created
July 12, 2022 02:03
-
-
Save ieatfood/2b3318b2aad28c19177d0ed9e10ec4b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns an array of the specified enum type with values that are the | |
* intersection of the array and enum type. | |
* | |
* Example: | |
* convertArrayToEnumType(["VISA", "CARTES_BANCAIRES"], AllowedCardNetworks) | |
* => ["VISA"] | |
*/ | |
export function convertArrayToEnumType<S, T extends string>(arr: Array<S>, type: Record<T, T>): Array<T> { | |
return arr.filter((k) => Object.keys(type).includes((k as unknown) as T)).map((k) => (k as unknown) as T); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment