Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong code for indexed generic in returned type #23

Closed
timocov opened this issue Sep 23, 2021 · 0 comments · Fixed by #24
Closed

Wrong code for indexed generic in returned type #23

timocov opened this issue Sep 23, 2021 · 0 comments · Fixed by #24
Labels
bug Something isn't working

Comments

@timocov
Copy link
Owner

timocov commented Sep 23, 2021

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;
@timocov timocov added the bug Something isn't working label Sep 23, 2021
timocov pushed a commit that referenced this issue Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant