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

Type guards wrapped in lambda lose the guard type #21310

Closed
jovdb opened this issue Jan 19, 2018 · 2 comments
Closed

Type guards wrapped in lambda lose the guard type #21310

jovdb opened this issue Jan 19, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@jovdb
Copy link

jovdb commented Jan 19, 2018

TypeScript Version: 2.7.0-dev.20180119

Search Terms:
array guard lambda

Code

declare function isString(arg: any): arg is string;

var items: (number | string)[] = [];
var a = items.filter(isString); // a: string[]
var b = items.filter(i => isString(i)); // b: (string | number)[]

When guard is wrapped in a lambda, guard type is gone
Other example:

// Get non-empty strings
var c = items.filter(i => isString(i) && i.length > 0); // c: (string | number)[]

Expected behavior:
b: string[]

Actual behavior:
b: (string | number)[]

Playground
link

Related Issues:
#18562

@mhegazy
Copy link
Contributor

mhegazy commented Jan 19, 2018

Duplicate of #5101 and #20812

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jan 19, 2018
@DanielRosenwasser DanielRosenwasser changed the title Type guards wrapped in lambda loose the guard type Type guards wrapped in lambda lose the guard type Jan 20, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants