Created
October 27, 2022 12:57
-
-
Save jsCommander/82d9e8693c177bd17ca6cf7a56ac5ed1 to your computer and use it in GitHub Desktop.
Get type of obj value
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
function shit<T extends {}, K extends keyof T>(obj: T, key: K): T[K] { | |
return obj[key]; | |
} | |
const x: {name: string; value: number} = { | |
name: '420', | |
value: 228, | |
}; | |
const y = shit(x, 'name'); // string | |
const z = shit(x, 'value'); // number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment