TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms:
Code
need something like [string, string, ...argv] or [string, string] & string[]
abc(['', '', ''])
function abc(data: [string, string] & string[]){}
Expected behavior:
allow a array with length >= 2
Actual behavior:
array length only allow 2
Playground Link:
Related Issues:
type ArrayTwoOrMore<T> = {
0: T
1: T
} & Array<T>
declare function abc(data: ArrayTwoOrMore<string>)
abc([]) // got expected error
abc(["a"]) // got expected error
abc(["a", "b"]) // no error
abc(["a", "b", "c"]) // no error
Edit: Converted to stackoverflow question since I didn't notice any already existing: https://stackoverflow.com/questions/49910889/typescript-array-with-minimum-length
@kpdonn thx
@kpdonn hmm
there has something happen when i use ...argv
console.log(abc([str, n, s])); // => no error
console.log(abc([str, n, s, ...argv])); // => error

@bluelovers It looks like spreading argv causes it to see the entire expression as just string[] and lose the information about the earlier indices. It might be worth opening a new issue specifically about that case since it might be considered a bug. Seems like one to me anyway.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Most helpful comment
Playground link
Edit: Converted to stackoverflow question since I didn't notice any already existing: https://stackoverflow.com/questions/49910889/typescript-array-with-minimum-length