Skip to content

Instantly share code, notes, and snippets.

@xjamundx
Created June 30, 2017 01:02
Embed
What would you like to do?
// 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