'Return type based on the enum parameter

I have a function e.g.

type DataType = 'json' | 'txt';
interface MyType {}

const getItem = <T extends string | MyType>(type: DateaType): T => axios.get<T>('...');

const r1: MyType = getItem('json');
const r2: string = getItem('txt');

Is there an option to apply conditional types to make the return type as strict as it is shown in the example?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source