Created
October 4, 2025 16:22
-
-
Save davidystephenson/6d27f7fcba6d7b5fb12ba3348d545905 to your computer and use it in GitHub Desktop.
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
| const o = { message: 'hi', count: 5 } | |
| // type Output = { | |
| // message: string | |
| // count: number | |
| // } | |
| type Output = typeof o | |
| const results = [] | |
| function getValue <T extends keyof Output> (data: Output, key: T) { | |
| console.log(`I will get the ${key} from the data`) | |
| const value = data[key] | |
| results.push(value) | |
| return value | |
| } | |
| const message = getValue<'message'>(o, 'message') | |
| function capitalize (text: string) { | |
| console.log(text.toUpperCase()) | |
| } | |
| capitalize(message) | |
| const count = getValue(o, 'count') | |
| function fix (number: number) { | |
| console.log(number.toFixed(2)) | |
| } | |
| fix(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment