Created
May 16, 2025 18:11
-
-
Save tomfa/71602edc0ce0877d02c7016aa7891a44 to your computer and use it in GitHub Desktop.
TS generic type, but with autocomplete suggestions
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
// (string & {}) defers collapsing of type, showing your | |
// suggested values as autocompletable. | |
// https://www.youtube.com/watch?v=lraHlXpuhKs&t=481s | |
const Brand = 'Audi' | 'BMW' | 'Volvo' | (string & {}); | |
const drive = (brand: Brand) => { | |
console.log(`${brand} goes wroom wroom!`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment