How can this convert
function check if value is of type KeysB
conditionally and return different value / do something else.
type KeysA = 'itemA' | 'extraB';
type KeysB = 'A' | 'itemB';
// at the moment this errors because the function doesn't return the expected type. The defined return type here is correct.
const convert = <E extends KeysA | KeysB>( value: E): E extends KeysB ? `key_${E}` : E => {
// if 'value' is TypeB then?
//return `key_${value}`;
// otherwise return value
return value;
}
// test
const key1 = convert('itemA'); // return 'itemA'
const key2 = convert('extraB'); // return 'extraB'
const key3 = convert('A'); // return 'key_A'
const key4 = convert('itemB'); // return 'key_itemB'