ts-reset icon indicating copy to clipboard operation
ts-reset copied to clipboard

custom filter callback not inferred when rule applied

Open ssukienn opened this issue 2 years ago • 2 comments

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

ssukienn avatar Dec 06 '23 14:12 ssukienn

What rule? Can you link to the minimal reproduction repo with only ts-reset and typescript as dependency?

qb20nh avatar Jan 25 '24 09:01 qb20nh

Hi, apologies for the clumsy example. Edited the msg and added playground

I believe the rule is @total-typescript/ts-reset/filter here

ssukienn avatar Jan 25 '24 09:01 ssukienn