Suppose I have this type defined in my app:
type PiiType = \'name\' | \'address\' | \'email\';
I u
The trick is to run the array through an identity function that infers an element type constrained by string. That will cause the compiler to infer a union of literal types:
function asLiterals(arr: T[]): T[] { return arr; }
const piiTypeValues = asLiterals(['name', 'address', 'email']);
type PiiType = (typeof piiTypeValues)[number];
There's another solution here but the above seems a bit simpler.