Skip to content

given x : T, bool should be a subtype of x is T #19557

Closed

Description

@acertain

If x : T is already known, any bool implies/is evidence for x is T.

This should help type inference for e.g.

function f<T, R extends T>(x: T[], p: (x: T) => x is R): R | undefined {
  for (const v of x) {
    if(p(v)){return v}
  }
}

// doesn't work
f([2,3,4], (x) => x > 3)
// works
f([2,3,4], (x): x is number => x > 3)

(filter, etc)

Activity

  1. changed the title [-]given `x : T`, `bool` should be a subtype of `x is T`[/-] [+]given x : T, bool should be a subtype of x is T[/+] on Oct 29, 2017
  2. aluanhaddad commented on Oct 30, 2017

    @aluanhaddad
    Contributor

    This looks like a duplicate of #10734

  3. typescript-bot commented on Nov 14, 2017

    @typescript-bot
    Contributor

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

  4. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions