Skip to content

Can't use is type asserting function as predicate parameter #19642

Closed

Description

@timm-gs

TypeScript Version: 2.5.3 and 2.7.0-dev.20171101

Code

type T1 = { t: 1 };
type T2 = { t: 2 };

function isT1(x: any): x is T1 {
    return x.t === 1;
}

function isT2(x: any): x is T2 {
    return x.t === 2;
}

function f(p: typeof isT1 | typeof isT2) {
    
} 

f(isT1);
f(isT2); // fails

Playground link

Expected behavior:
It compiles

Actual behavior:
Fails to compile:

Argument of type '(x: any) => x is T2' is not assignable to parameter of type '(x: any) => x is T1'.
  Type predicate 'x is T2' is not assignable to 'x is T1'.
    Type 'T2' is not assignable to type 'T1'.
      Types of property 't' are incompatible.
        Type '2' is not assignable to type '1'

Activity

  1. ghost added
    DuplicateAn existing issue was already created
    on Nov 1, 2017
  2. ghost added a commit that references this issue on Nov 1, 2017
  3. typescript-bot commented on Nov 16, 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. ghost added a commit that references this issue on Dec 5, 2017
  5. locked and limited conversation to collaborators on Jul 3, 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

    DuplicateAn existing issue was already createdFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions