I am encountering a situation where I receive a response from Node.js that includes multiple data types such as
string | QueryString.ParsedQs | string[] | QueryString.ParsedQs[]
. However, I specifically require it to be only of type string[]
. How can I achieve this in TypeScript?
To provide some context: the challenge arises because Node.js returns
string | QueryString.ParsedQs | string[] | QueryString.ParsedQs[]
when accessing req.query
, but it is crucial for me to have it as a string[]
, especially when using TypeORM with a where-in clause.
Below is the code snippet I have tried so far, which unfortunately does not yield the desired outcome:
import { In } from "typeorm";
const { investmentIds } = req.query;
const historicalReturns = await historicalReturnRepository.find({
where: In(investmentIds)
});