Hi,
acutal I'm writing a generic function, which searches an entity by a given column and it's value. The code looks like this so far:
async findByColumn(
columnName: string,
columnValue: number | string,
): Promise<T> {
const options: FindOptionsWhere<T> = {
columnName: columnValue,
} as unknown as FindOptionsWhere<T>;
return this.findOneBy(options);
}
The issue is, if I call this method, I get the error that 'Property "columnName" was not found in "User". Make sure your query is correct.'. Which means of course, that the 'columnName' wasn't replaced with the 'columnName' variable from the method signature. Beside of that I know, that using 'unknown' is also bad in this case.
So the question is, how should I rewrite this?