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
void
Inside TSReset.NonFalsy, void is not considered falsy. That leads to incorrect behavior of .filter(Boolean)
TSReset.NonFalsy
.filter(Boolean)
declare namespace TSReset { type NonFalsy<T> = T extends false | 0 | '' | null | undefined | 0n ? never : T; } interface Array<T> { filter(predicate: BooleanConstructor, thisArg?: any): TSReset.NonFalsy<T>[]; } const fns = [ (x?: unknown) => 1, () => {}, ]; const nonEmptyResults = fns.map(fn => fn()).filter(Boolean) // ^? const nonEmptyResults: (number | void)[]
TS Playground Example
The text was updated successfully, but these errors were encountered:
It's a nice idea, but making void falsy is not safe. Functions with a void return type can still return a truthy value. See https://www.typescriptlang.org/docs/handbook/2/functions.html#return-type-void
Sorry, something went wrong.
@russelldavis Yeah, I guess that makes sense, thanks
Successfully merging a pull request may close this issue.
Inside
TSReset.NonFalsy
,void
is not considered falsy. That leads to incorrect behavior of.filter(Boolean)
TS Playground Example
The text was updated successfully, but these errors were encountered: