We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Boolean refine wrapped
My suggestion meets these guidelines:
if you wrap a value in Boolean() and use it in a conditional, it should still refine it to be not null or undefined.
Boolean()
In JSX its common to do the following
x && <Component x={x} />
but we have issues where if x is falsy but not accepted as a non value in jsx it can leak the type, so there is a lint rule to protected against it
https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-leaked-render.md
the least invasive fix of the lint rule is to wrap x in Boolean
Boolean(x) && <Component x={x} />
but that breaks typescripts ability to refine x.
example:
function a(x: undefined|null|{a: boolean}) { Boolean(x) && b(x); } function b(x: {a: boolean}) { }
It is possible to fix this with something like this
interface BooleanConstructor { <T extends {} | string | number | boolean | Array<any>>( value?: T | undefined | null | '' | false, ): value is T; }
playground link
Is there a reason to not have the above in the library - does it make typescript slower?
The text was updated successfully, but these errors were encountered:
Another duplicate of #16655.
Sorry, something went wrong.
Thanks, I did search and didn't find that one.
No branches or pull requests
Suggestion
π Search Terms
Boolean refine wrapped
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
if you wrap a value in
Boolean()
and use it in a conditional, it should still refine it to be not null or undefined.π Motivating Example
In JSX its common to do the following
but we have issues where if x is falsy but not accepted as a non value in jsx it can leak the type, so there is a lint rule to protected against it
https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-leaked-render.md
the least invasive fix of the lint rule is to wrap x in Boolean
but that breaks typescripts ability to refine x.
example:
It is possible to fix this with something like this
playground link
Is there a reason to not have the above in the library - does it make typescript slower?
The text was updated successfully, but these errors were encountered: