-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Inconsistent behavior for forEach and map when using conditional type #36521
Comments
Looks like another duplicate of #7294, mentioned in documentation as caveats for improved behavior for calling union types:
|
I'm not sure if it's the same thing, I just edited my issue I think it was misleading, the issue I'm reporting is that typescript should have same behavior for |
Please read the TS3.3 release notes for Improved behavior for calling union types, including the full Caveats section, and let me know if there's something in your issue that isn't covered by that. |
It's explicitly said in the caveats that |
I just noticed that issue is closed without resolving the issue described here, so I guess it should stay open. |
|
@RyanCavanaugh |
@sassanh Please don't tell us our what our own metadata means. For us, "Open" means that we have the ability to schedule engineering work to address the problem; "Closed" means that it doesn't. This issue being closed doesn't mean that we're unaware of the limitation. |
I wasn't telling you what your metadata mean, I'm sorry if it was interpreted that way, I among many others usually use issue trackers to reflect "awareness" about problems on it and we usually close an issue only when it's resolved, seems like it's different here, is there any document explaining how issues are tracked in TypeScript repository that I can read so that I can avoid such misunderstandings and stay productive in my future bug reports? |
Fair enough; I owe you a FAQ update on that one |
Is there any workaround for the issue?
Ho @sassanh I dream of a world where one doesn't fear to comment on <GITHUB | STACK OVERFLOW | REDIT | any> it may seem rude to say «Please don't tell us[...] what our own metadata means.» it did to me but I don't want to be unconstructive... the rest of the comment is interesting and important to me because I didn't know that «For [you], "Open" means that [you] have the ability to schedule engineering work to address the problem; "Closed" means that it doesn't. This issue being closed doesn't mean that [you're] unaware of the limitation.» Maybe my code is just wrong and I don't knowMy code: public listMap<R>(
fn: (
value: T | Promise<T>,
index: number,
array: T[] | Promise<T>[]
) => R | Promise<R>,
thisArg?: any
) {
if (this.value !== null) {
return new MaybeList<R>(this.value.map<R>(fn, thisArg))
}
return new MaybeList<null>();
}
error message: (
|
TypeScript Version: 3.8.0-dev.20200128
Search Terms:
Code
Expected behavior:
Typescript to either can determine the signature of both the
map
callback ANDforEach
callback or to understand none.Actual behavior:
It doesn't have any problem with
forEach
but raises this error for themap
clause:Playground Link:
http://www.typescriptlang.org/play/?ts=3.8.0-dev.20200128&ssl=9&ssc=1&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgMoQWYB7EAeAFWQgA9IQATAZ2RAFcBbAI2mQB9kqwpQBzAPmQBvAFDJkwSAyoAuZEVLlqtRiyjIA-CubQA2gF1kcrjxC8DAbhEBfESNIAHbFDDIYdEJhwhkkLoWIyCEoaeh11DhM+fgAKOCheOXQvXEJ+AEo5ADdsYAphMWR43gA6SQhpEphnAFFEAAsYmMzkHLzkAF5BBFwqbAAbCBL+7F5m9KtxYrKpKhKGOAcmlrb8ruQekD7B4dHxq1sgA
Related Issues:
#33591
Changing the type of the
items
field tomakes it compile without any errors.
The text was updated successfully, but these errors were encountered: