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

unicorn/prefer-native-coercion-functions doesn't work well with typescript and should be disabled. #242

Open
hjeti opened this issue Mar 1, 2024 · 2 comments

Comments

@hjeti
Copy link

hjeti commented Mar 1, 2024

The Boolean part of this rule and the auto fix break my code, because they don't work well with typescript.

I write this:

const testArray = ['test', null];
        
const output = testArray.filter((value): value is string => Boolean(value));

and it converts it to this:

const testArray = ['test', null];

const output = testArray.filter(Boolean);

This is not the same. The type of output is Array<string> in my code and Array<string | null> in the 'autofixed' code.

@ThaNarie
Copy link
Member

ThaNarie commented Mar 1, 2024

It seems there is an open issue for this: sindresorhus/eslint-plugin-unicorn#1857

Alternative option is to use isBoolean from isntnt, which is typeguarded.

But it seems that, until that issue is fixed, we should disable it.

@leroykorterink
Copy link
Collaborator

Typescript now infers type predicates properly, but with this change I think we should disallow the use of the Boolean constructor as an argument for the Array.filter function.

https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-beta/#inferred-type-predicates

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

3 participants