Created
May 15, 2019 17:41
-
-
Save Announcement/de0d2c35dd7ffd5dd484816635b23ea7 to your computer and use it in GitHub Desktop.
why is {[key: string]: T} not { x: number }
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Matrix { | |
readonly [index: number]: { | |
readonly [index: number]: number; | |
}; | |
} | |
interface CartesianPoint { | |
x: number; | |
y: number; | |
z: number; | |
} | |
function generateMatrix_nPoints(...points: CartesianPoint[]): Matrix { | |
return [ | |
[...points.map(property('x'))], | |
[...points.map(point => point.y)], | |
[...points.map(point => point.z)] | |
]; | |
} | |
function property (name: string) { | |
return function<T> (input: { [key: string]: T }): T { | |
return input[name]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You’ll have to defer the checking to runtime and cast it manually: