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

custom filter callback not inferred when rule applied #178

Open
ssukienn opened this issue Dec 6, 2023 · 2 comments
Open

custom filter callback not inferred when rule applied #178

ssukienn opened this issue Dec 6, 2023 · 2 comments

Comments

@ssukienn
Copy link

ssukienn commented Dec 6, 2023

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
Copy link

qb20nh commented Jan 25, 2024

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

@ssukienn
Copy link
Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants