A library I'm using exports a type like this:
type Pet = 'dog' | 'cat' | 'rat';
I want to now make a dropdown that has all these values in my UI. I am not able to enumerate this const type. So I thought to make an array of these values and type it such that it must have exactly one of each const in the type Pet
but can't figure this out.
I tried the following but it doesn't cause error when more keys are added to Pet
. I want typescript to fail on build when I update the lib and the lib decided to add more consts.
type Pet = 'dog' | 'cat' | 'rat';
const pets: Pet[] = ['dog', 'dog']; // this should error as its missing "cat" and "rat". and also it has "dog" twice.