How to check user input is a valid column before appending condition?

Does anyone knows the proper way to do so?
 if (columnFilters.length > 0) {
  const columnWhereClause: (SQL | undefined)[] = columnFilters.map(
    (filter) => {
      const columns = getTableColumns(tasks);

      if (filter.column in columns) {
        // getting error on columns[filter.column]: type 'string' can't be used to index type 
        return ilike(columns[filter.column], `%${filter.keyword}%`);
      }
    },
  );
  whereClause.push(and(...columnWhereClause));
}
Was this page helpful?