Wrong code for indexed generic in returned type
timocov opened this issue · comments
Evgeniy Timokhov commented
Bug report
Input code
export interface Ohlc {
open: number;
high: number;
low: number;
close: number;
}
export interface BarValueByType {
Bar: Ohlc;
Line: number;
}
export type SeriesType = keyof BarValueByType;
export function getBarValue<T extends SeriesType>(value: number, seriesType: T): BarValueByType[T] {
if (seriesType === 'Bar') {
return {
open: value,
high: value,
low: value,
close: value,
} as BarValueByType[T];
} else {
return value as BarValueByType[T];
}
}
Expected output
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBarValue = void 0;
function getBarValue(value, seriesType) {
if (seriesType === 'Bar') {
return {
open: value,
high: value,
low: value,
close: value,
};
}
else {
return value;
}
}
exports.getBarValue = getBarValue;
Actual output
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBarValue = void 0;
function getBarValue(value, seriesType) {
if (seriesType === 'Bar') {
return {
_internal_open: value,
_internal_high: value,
_internal_low: value,
_internal_close: value,
};
}
else {
return value;
}
}
exports.getBarValue = getBarValue;