Skip to content

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

@timm-gs

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'

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