I want to be able to define an array that contains exactly the elements of all possible values of a union once.
type Union = "prevStep" | "nextStep" | "submit" | "order";
// this works:
const list: LiteralList<Union> = ["nextStep", "order", "prevStep", "submit"];
// this fails:
const list: LiteralList<Union> = ["nextStep", "order", "prevStep", "submit", "submit"];
// this fails:
const list: LiteralList<Union> = ["nextStep", "order", "prevStep"];
I already made this work with this type:
type LiteralList<T extends string, U = T> = [T] extends [never]
? []
: U extends T
? [U, ...LiteralList<Exclude<T, U>>]
: [];
I'm not sure though if it makes sense since I asked ChatGPT to do it.
Is it possible to add this type helper to type-fest?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too