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

Predicates break arbitrarily when intersected with some types. (Probably when the predicate is generic). #60048

Open
miguel-leon opened this issue Sep 24, 2024 · 0 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@miguel-leon
Copy link

πŸ”Ž Search Terms

predicate intersection

πŸ•— Version & Regression Information

latest version v5.6.2

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.2#code/JYOwLgpgTgZghgYwgAgCpQK5gBYE8AKUEAJsAnJMgN4CwAUMo8gDyoB8AFAPYBcaAlHy7JgAZzTIAZNQC+Abnoz69UJFiIUAUQC2ABzC4AkuGjwk1RcroHdKAMJcQosJgRguUAMrAA5iDg+GETIALwWDEwgEADuyBwAdIlwUD6ifHAguADaALqCyBm4CnTyVsQQCAA2ySgIjs4FUFB8HM5QoD7IAD7IGCDlMKAk-LnF9OVVNch1TmDIukSk5JAAjHzoWHiEJGQUEMUzDYOVaiQroY1Q8cdqHAs7yxAr-HLIAPRvyNEeANbibR1clZxhVqsFDnN7ks9gAmdaYHAERa7SjSHT6IwmdRIA71OY3aAkGEXZJXAlQO7Ix4wl7vT7ELgQUQgADkc2+UB+wLoEzBtTx8ypewAzPDNkiHnspLJcbNkOSSMKSU1rsATtBKZLIMLaR8vr9-i5ATlubyphDBVqIAAWMWI7bQ1HIByzVzuLy+fyBIiyo5q07Ea3Ksn+jVQlE23X0xnMtn6zn0IA

πŸ’» Code

interface TruthyPredicate {
    <T>(o: T): o is T & {};
}

interface EmptyInterface {
}

type ConstructorSignagure = {
    new (...args: any[]): any;
};

declare const arr: (string | undefined)[];

declare const predicate1: TruthyPredicate;
const filtered1 = arr.filter(predicate1); // works string[]


declare const predicate2: TruthyPredicate & EmptyInterface;
const filtered2 = arr.filter(predicate2); // doesn't work


declare const predicate3: TruthyPredicate & {} /* Empty object type instead of interface */;
const filtered3 = arr.filter(predicate3); // works string[]


declare const predicate4: TruthyPredicate & ConstructorSignagure;
const filtered4 = arr.filter(predicate4); // doesn't work

πŸ™ Actual behavior

Predicate stops working

πŸ™‚ Expected behavior

Predicate works

Additional information about the issue

I tried other scenarios

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Sep 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants