You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeNonEmptyArray<T>=[T, ...T[]]consta=[1,2,3]asconstfunctionfn<T>(a: NonEmptyArray<T>){returna}fn(a.map((v)=>v))// Argument of type '(1 | 2 | 3)[]' is not assignable to parameter of type 'NonEmptyArray<1 | 2 | 3>'. Source provides no match for required element at position 0 in target.(2345)
🙁 Actual behavior
TypeScript complains that a.map((v) => v)) is not a valid input for fn as it might be missing an element at position 0.
🙂 Expected behavior
I might be mistaken, but I understand that map guarantees an array of equal length, which in this case would guarantee an element at position 0.