3

I have a union of 3 possible strings:

type AllowedWords = "one" | "two" | "three";

I want to create a template literal type that allows any of those 3 words in any order, but each member should only be included up to once. For example, this should be an exhaustive list of all possible matches:

  • one
  • two
  • three
  • onetwo
  • onethree
  • twoone
  • twothree
  • threeone
  • threetwo
  • onetwothree
  • onethreetwo
  • twoonethree
  • twothreeone
  • threeonetwo
  • threetwoone

How can I define a type that represents that?

Michael Hulet
  • 3,253
  • 1
  • 16
  • 33
  • Yeah I was going to point to that one too... you can do something like [this](https://tsplay.dev/N71EBW) but oh boy does it get unwieldy quickly – jcalz Aug 08 '22 at 22:39
  • 3
    @Nenad this allows duplicate elements. The linked answer does not and the question mentions *"each member should only be included up to once"*. Also, if you believe there is a better answer to a question, you should post the better answer as an answer to the older post. But duplicate questions should be closed as duplicates. – Tobias S. Aug 08 '22 at 22:47
  • @TobiasS. OK, I see the difference related to the *duplicate elements*. However, original question and answer are noisy and less readable, that's where I'm not sure if this should have been deleted, in favor of the other one. – Nenad Aug 10 '22 at 16:47

0 Answers0