I want to somehow achieve something like this in typescript:
export type CoordinateSelector = <T>(d: Coordinate) => d[T];
export interface LinkVerticalLineProps {
x: CoordinateSelector<'x'>;
y: CoordinateSelector<'y'>;
}
I don't want to create x and y coordinate selectors like this:
export interface LinkVerticalLineProps {
x: (d: {x: number}) => d.x;
y: (d: {y: number}) => d.y;
}
Is this type of thing possible?
Coordinate? Are you just asking fortype CoordinateSelector<K extends keyof Coordinate> = (d: Coordinate) => Coordinate[K]maybe? I'm not sure what you mean since the code you wrote at the bottom does not compile.