-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Proposal: Add not
#32
Comments
Is inverting the return type of a type guard possible with TypeScript's type system? |
It depends on microsoft/TypeScript#4183 (comment) type Predicate<Type> = (value: unknown) => value is Type;
function not<Type>(predicate: Predicate<Type>) {
return <Value>(value: Value): value is Exclude<Value, Type> => !predicate(value);
};
const isNullable = (value: unknown): value is null | undefined =>
value === null || value === undefined;
const isNonNulluable = not(isNullable);
//=> <Value>(value: Value) => value is Exclude<Value, null | undefined> use-cases:
|
@younho9 I don't think this will work with |
Yes, when this PR merge, the negated type guards will be more useful. Negative type guards (with
But I still think some types guards with |
Related type-only request: |
It could be useful to reuse existing predicate.
use-case: TypeScript Playground
The text was updated successfully, but these errors were encountered: