Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Supposedly) non-empty array causes "Source provides no match for required element at position 0 in target.(2345)" #53698

Closed
twiddler opened this issue Apr 7, 2023 · 2 comments

Comments

@twiddler
Copy link

twiddler commented 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

type NonEmptyArray<T> = [T, ...T[]]

const a = [1, 2, 3] as const

function fn<T>(a: NonEmptyArray<T>) {
    return a
}

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. 🙏

@twiddler 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
@jcalz
Copy link
Contributor

jcalz commented Apr 7, 2023

Essentially a duplicate of #29841

@twiddler
Copy link
Author

twiddler commented Apr 7, 2023

I think so, too. Thanks!

@twiddler twiddler closed this as not planned Won't fix, can't repro, duplicate, stale Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants