Skip to content

custom filter callback not inferred when rule applied #178

Description

@ssukienn

Hi,

// you need to save/refresh page in playground to get rid of effect after (un)comment
// import '@total-typescript/ts-reset';

const isPropTruthy = <T, K extends keyof T>(propName: K) => {
  return (item: T): item is T & Required<Pick<T, K>> => !!item[propName];
};

interface User {
 id?: string,
 //...
} 

const client = {
    deleteUser: (id: string) => {}
};


([] as User[])
        .filter(isPropTruthy('id'))
        .map((user) => client.deleteUser(user.id)); // inferred as User & Required<Pick<User, 'id'>

//no rule
// no errors

//with rule
//  error TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
//  error TS2339: Property 'id' does not exist on type 'Required<Pick<unknown, never>>'.

playground

Any idea what's causing inference to stop working?

Thank you!

tsc 5.3.2

Activity

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

    bugSomething isn't workingneeds-triageMaintainer needs to evaluate this issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions