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.
Thanks for your help. 🙏
The text was updated successfully, but these errors were encountered:
twiddler
changed the title
Non-empty array causes "Source provides no match for required element at position 0 in target.(2345)"
(Supposedly) non-empty array causes "Source provides no match for required element at position 0 in target.(2345)"
Apr 7, 2023
Bug Report
🔎 Search Terms
map source provides no match nonempty
🕗 Version & Regression Information
This happens in nightly, 5.0.3, 3.3.3 (similar error message) and many more versions available in the playground.
I reviewed the FAQ for entries about Common "Bugs" That Aren't Bugs.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
TypeScript complains that
a.map((v) => v))
is not a valid input forfn
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.
Thanks for your help. 🙏
The text was updated successfully, but these errors were encountered: