total-typescript / ts-reset

A 'CSS reset' for TypeScript, improving types for common JavaScript API's
https://www.totaltypescript.com/ts-reset
MIT License
7.74k stars 117 forks source link

custom filter callback not inferred when rule applied #178

Open ssukienn opened 7 months ago

ssukienn commented 7 months ago

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

qb20nh commented 6 months ago

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

ssukienn commented 6 months ago

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

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