Repository navigation
Array/Observable filter does not infer chained type #19640
Description
Activity
I noticed this by a different case actually, probably should have posted that one.
['foo', 'bar', null] .filter(Boolean) .map(s => s.toUpperCase());
This worked with TS ~2.3 and is not working anymore with TS ~2.6. I thought the above would be a simpler reproduction but it seems it is something completely different :) Thanks for your hint though, this helps but still required quite a few new guards in our codebase which worked in a previous TS version 😕
You're right doesn't work on arrays, we do have some rxjs observables where this works though, no idea what exactly is different there or if it's project specific.. I will report back later this week.
- addedDuplicateAn existing issue was already createdAn existing issue was already created
on Nov 1, 2017 typescript-bot commented
on Nov 17, 2017 ContributorMore actionsAutomatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Jan 11, 2018 A user-defined type guard is not inferred automatically, a type annotation is expected. i.e.:
const list: (string | null)[] = ['A', null, 'C'] function isNotNull<T>(a: T | null): a is T { return a !== null; } list.filter(isNotNull).map(x => x.)
Reacted by Zack Ream, Alexander von Weiss and Vlad SabevA user-defined type guard is not inferred automatically, a type annotation is expected. i.e.:
It is good to hear, but still complicated, not clear whey it not possible to have auto inference here.
- locked and limited conversation to collaborators
on Jul 3, 2018

TypeScript Version: 2.6.1 using
strict: trueCode
Expected behavior:
Compiles
Actual behavior: