Skip to content

Instantly share code, notes, and snippets.

@yamafaktory
Created November 21, 2019 13:24
Show Gist options
  • Save yamafaktory/c8a9296c18e2d5be9e0021e24e1f3bde to your computer and use it in GitHub Desktop.
Save yamafaktory/c8a9296c18e2d5be9e0021e24e1f3bde to your computer and use it in GitHub Desktop.
πŸ” Typecheck object properties from array elements in TypeScript
const MY_ARRAY = ['a', 'b', 'c'] as const
const objectWithKeysFromConstArrayElements: Record<
typeof MY_ARRAY[number],
string
> = { a: 'foo', b: 'bar', c: 'foobar' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment