How can you create a type in TypeScript that only accepts arrays with two or more elements?
needsTwoOrMore([\"onlyOne\"]) // should have error
needsTwoOrMore
This can be accomplished with a type like:
type ArrayTwoOrMore = {
0: T
1: T
} & Array
declare function needsTwoOrMore(arg: ArrayTwoOrMore): void
needsTwoOrMore(["onlyOne"]) // has error
needsTwoOrMore(["one", "two"]) // allowed
needsTwoOrMore(["one", "two", "three"]) // also allowed
TypeScript Playground Link