Skip to content

Instantly share code, notes, and snippets.

@erikras
Created November 11, 2021 11:49
Show Gist options
  • Save erikras/9f394feaba6e0aff39b7b9e391cd5864 to your computer and use it in GitHub Desktop.
Save erikras/9f394feaba6e0aff39b7b9e391cd5864 to your computer and use it in GitHub Desktop.
TypeScript trick to use the id type off of an object.
function selectTask(taskId: string) {
// This is okay, but it might require refactoring if the taskId type ever changes
}
function selectTask(taskId: Task['id']) {
// Much better. We don't care what type the taskId is.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment