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

Narrow types when using Array.filter #2835

Closed
NoelAbrahams opened this issue Apr 20, 2015 · 1 comment
Closed

Narrow types when using Array.filter #2835

NoelAbrahams opened this issue Apr 20, 2015 · 1 comment
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@NoelAbrahams
Copy link

Hi,

Will this be possible?

var foo: (number|string)[] = [1, 'bar'];

foo.filter(item => typeof item ==='string').map(item => item/*string type*/);
foo.filter(item => typeof item !=='string').map(item => item/*number type*/);
@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds labels Apr 20, 2015
@RyanCavanaugh
Copy link
Member

Not happening unless someone can figure out a reasonable way to write a signature for filter in a way that is generalizable.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

2 participants