Skip to content

Instantly share code, notes, and snippets.

@tomfa
Created May 16, 2025 18:11
Show Gist options
  • Save tomfa/71602edc0ce0877d02c7016aa7891a44 to your computer and use it in GitHub Desktop.
Save tomfa/71602edc0ce0877d02c7016aa7891a44 to your computer and use it in GitHub Desktop.
TS generic type, but with autocomplete suggestions
// (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