diff --git a/client/src/app/pages/applications/components/application-form/application-form.tsx b/client/src/app/pages/applications/components/application-form/application-form.tsx index 476175bea0..909dc0eda4 100644 --- a/client/src/app/pages/applications/components/application-form/application-form.tsx +++ b/client/src/app/pages/applications/components/application-form/application-form.tsx @@ -597,7 +597,7 @@ const useApplicationFormData = ({ // Fetch data const { tagCategories } = useFetchTagCategories(); const tags = useMemo( - () => tagCategories.flatMap((tc) => tc.tags).filter(Boolean) as Tag[], + () => tagCategories.flatMap((tc) => tc.tags).filter(Boolean), [tagCategories] ); diff --git a/client/src/app/utils/model-utils.tsx b/client/src/app/utils/model-utils.tsx index 5488be59b6..1136fad3ee 100644 --- a/client/src/app/utils/model-utils.tsx +++ b/client/src/app/utils/model-utils.tsx @@ -229,7 +229,7 @@ export const toRef = ( export const toRefs = ( source: Iterable ): Array | undefined => - !source ? undefined : ([...source].map(toRef).filter(Boolean) as Ref[]); + !source ? undefined : [...source].map(toRef).filter(Boolean); /** * Take an array of source items that look like a `Ref`, find the first one that matches @@ -271,11 +271,11 @@ export const matchItemsToRefs = ( ): Array | undefined => !matchValues ? undefined - : (matchValues + : matchValues .map((toMatch) => !toMatch ? undefined : items.find((item) => matchOperator(itemMatchFn(item), toMatch)) ) .map(toRef) - .filter(Boolean) as Ref[]); + .filter(Boolean); diff --git a/client/types/array-filter-Boolean.ts b/client/types/array-filter-Boolean.ts new file mode 100644 index 0000000000..741e1c984b --- /dev/null +++ b/client/types/array-filter-Boolean.ts @@ -0,0 +1,28 @@ +/** + * Fixes https://github.com/microsoft/TypeScript/issues/16655 for `Array.prototype.filter()` + * For example, using the fix the type of `bar` is `string[]` in the below snippet as it should be. + * + * const foo: (string | null | undefined)[] = []; + * const bar = foo.filter(Boolean); + * + * For related definitions, see https://github.com/microsoft/TypeScript/blob/master/src/lib/es5.d.ts + * + * Original licenses apply, see + * - https://github.com/microsoft/TypeScript/blob/master/LICENSE.txt + * - https://stackoverflow.com/help/licensing + */ + +/** See https://stackoverflow.com/a/51390763/1470607 */ +type Falsy = false | 0 | "" | null | undefined; + +interface Array { + /** + * Returns the elements of an array that meet the condition specified in a callback function. + * @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. + * @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. + */ + filter( + predicate: BooleanConstructor, + thisArg?: any + ): Exclude[]; +}