Skip to content

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

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

Closed
timm-gs opened this issue Nov 1, 2017 · 2 comments
Closed

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

timm-gs opened this issue Nov 1, 2017 · 2 comments
Labels
Duplicate An existing issue was already created Fixed A PR has been merged for this issue

Comments

@timm-gs
Copy link

timm-gs commented Nov 1, 2017

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'
@ghost
Copy link

ghost commented Nov 1, 2017

Duplicate of #17757
Fixed by #17600

@ghost ghost marked this as a duplicate of #17757 Nov 1, 2017
@ghost ghost added the Duplicate An existing issue was already created label Nov 1, 2017
ghost pushed a commit that referenced this issue Nov 1, 2017
@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.

ghost pushed a commit that referenced this issue Dec 5, 2017
* Lazily compute signature type predicates

* Use an instance of IdentifierTypePredicate to represent an unresolved type predicate

* Simplify `getMaybeTypePredicate`

* Invert representation of `resolvedTypePredicate`

* Remove `__unresolvedTypePredicate` type and remember to use `noTypePredicate` instead of `undefined` when in all `createSignature` calls

* Fix style of getTypePredicateOfSignature

* Use in createGetSymbolWalker

* Fix bugs for unions of type predicates

* Code review

* Make noTypePredicate purely an implementation detail of getTypePredictateOfSignature

* Add test

* Add test for #19642

* Add test with reversed order
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 11, 2018
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Jan 11, 2018
@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 Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants