This file contains 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
// no types | |
function getFields(fields) { | |
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {}) | |
} | |
// no return type | |
function getFields(fields: Array<string>) { | |
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {}) | |
} | |
// generic string: string mapping | |
function getFields(fields: Array<string>): { [key: string]: string } { | |
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {}) | |
} | |
// TODO: figure out how to get a return type that understands the strings | |
// When `getFields(['a', 'b'])` then the return type should be `{ a: string, b: string }` | |
function getFields(fields: Array<string>) { | |
return fields.reduce((prev, curr) => (prev[curr] = curr, prev), {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment