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
This may be considered too specific - but the use case is very common so hopefully worth it.
Use Cases
This will allow using array.filter(Boolean) to get rid of null/undefined/falsy values, and have the type system track it correctly even with strictNullChecks.
Right now the options are to use lodash.compact or write a similar function (not ideal to add a dependency), or to use ! (myArray.filter(Boolean).map(val => val!.foo(...))) which is a little dangerous.
Jack Williams (@jack-williams) interesting, it'd be great if this could be solved by modifying the type of Boolean rather than filter. But I just tried manually putting in Forbes Lindesay (@ForbesLindesay) 's signature in typescript@next and it doesn't allow using .filter(Boolean) without explicitly supplying the generic i.e. .filter<string>(Boolean). That's fine-ish for strings but when it's a complex inferred type it wouldn't be feasible.
Activity
jack-williams commentedon Mar 27, 2019
See #29955
mmkal commentedon Mar 28, 2019
Jack Williams (@jack-williams) interesting, it'd be great if this could be solved by modifying the type of
Booleanrather thanfilter. But I just tried manually putting in Forbes Lindesay (@ForbesLindesay) 's signature intypescript@nextand it doesn't allow using.filter(Boolean)without explicitly supplying the generic i.e..filter<string>(Boolean). That's fine-ish for strings but when it's a complex inferred type it wouldn't be feasible.typescript-bot commentedon Mar 30, 2019
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
ForbesLindesay commentedon Apr 8, 2019
Misha Kaletsky (@mmkal) That can be fixed, but will require improvements to the inference engine.