const values = {
x: 1,
y: 2
}
/**
* @param {'x'|'y'} [key]
*/
function getValue(key) {
return values[key]
}
/**
* @typedef {('x' | 'y')} XValueKeys
*/
function getValue(/** XValueKeys */key) {
return values[key]
}
type XValues = {x: number, y: number};
const values: XValue = {x: 1, y: 2};
function getValue<K extends keyof XValues>(key: K): XValues[K] {
return values[key];
}