Created
November 11, 2021 11:49
-
-
Save erikras/9f394feaba6e0aff39b7b9e391cd5864 to your computer and use it in GitHub Desktop.
TypeScript trick to use the id type off of an object.
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
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