1

I need to have a type act like this exam

type uniqueArrayType = string[] // code here ;
const myUniqueArray :uniqueArrayType = ['string 1','string 2'] // will fit the type
const myUniqueArray2 :uniqueArrayType = ['str','str'] // will not fit the type

Mor Bargig
  • 198
  • 1
  • 7
  • 2
    No, there is no *specific* type that works this way. You could make a generic type constraint and a helper function like [this](https://tsplay.dev/WzOkLw), but it's complicated and fragile. See the other question for more info. – jcalz Apr 15 '22 at 15:24
  • @jcalz Could you please explain what means the `keyof any[] | I` part in your helper example? – Daniel Rodríguez Meza Apr 15 '22 at 16:53
  • `I` is the current numeric-like index of the tuple type (something like `"0"` or `"1"` or `"2"`, etc). For each index `I`, I want to make sure the `I`th element `T[I]` of the tuple is different from all the other ones; so I want to look at all the numeric-like array properties except `I`. `Exclude` is saying "give me all the keys of `T`, except for the general array ones (like `"length"` or `"pop"`), and except for `I`". – jcalz Apr 15 '22 at 19:20

0 Answers0