In the process of developing a library, I am seeking to enhance the accuracy of the Types provided. This would ensure that users of the library are unable to select the incorrect type in a scenario like the one outlined below.
The function described here will return either IPlayerStats
or IStatsItem[]
based on the true/false value of the convertJSONOutput
parameter.
public async getStatsById(
userId: string,
timeWindow: TimeWindow = TimeWindow.Alltime,
convertJSONOutput: boolean = true
): Promise<IPlayerStats | IStatsItem[]> {
// Ommitted
}
The query is:
Is it possible to define a conditional return type that determines which interface will be returned depending on the boolean value of the convertJSONOutput
parameter?