-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Cannot type flatMap polyfill #31015
Comments
What is the bug here? |
The 4 numbered under Actual behavior I would all qualify as bugs. I'm trying to track down related tickets (unsuccessful last night), but it's the first time ever (to its credit) using TypeScript that I've encountered several at once. I reported it as an umbrella issue, because it's not at all contrived code. I'm just trying to implement a type in the standard lib. Even if I break it down to individual tickets, I'd prefer to link back to my use case. I ran into an additional issue trying to implement this with JSDoc syntax, but I did find tickets related to that. |
1: I don't see this in 3.4 |
Thank you!
|
#28655 et al. with workaround.
Not without dancing around null checks, no. |
TypeScript Version: 3.4.3
Search Terms:
Code
Expected behavior:
This an umbrella issue. I ran into multiple issues trying to polyfill
Array#flatMap
without duplicating the type signature from"lib": ["esnext"]
:Actual behavior:
ReturnType<typeof Array.prototype.flatMap>
types as{}[]
.ElementType<ReturnType<typeof f>>
types asU | ElementType<U>
instead of unifying onU
.f.call(that, x, i, xs)
errors withArgument of type 'This | undefined' is not assignable to parameter of type 'This'.
.Array.isArray(y) ? ys.push(...y) : ys.push(y)
. The inferred types are(U | readonly U[]) ? (any[]) : (U | readonly U[])
. I suspect it has to do withreadonly
.Playground Link:
Not reproducible on the Playground, because it requires
"lib": ["esnext"]
. I could share a CodeSandbox, though.Related Issues:
The text was updated successfully, but these errors were encountered: