-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Closed
Copy link
Labels
Description
π Search Terms
{} undefined null predicate unknown narrowing
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about narrowing
β― Playground Link
π» Code
declare function isNotNullish(value: unknown): value is {};
declare function isNullish(value: unknown): value is null | undefined;
declare const value: unknown;
if (isNotNullish(value)) {
value;
// ^?
}
if (!isNotNullish(value)) {
value;
// ^?
}
if (isNullish(value)) {
value;
// ^?
}
if (!isNullish(value)) {
value;
// ^?
}π Actual behavior
value only narrows when the type predicate is called directly, not when negated with a !.
The narrowed types of value in that example are:
isNotNullish(value):{}!isNotNullish(value):unknownβisNullish(value):null undefined!isNullish(value):unknownβ
π Expected behavior
The narrowed types of value should be:
isNotNullish(value):{}!isNotNullish(value):null | undefinedisNullish(value):null undefined!isNullish(value):{}
Additional information about the issue
No response
uhyo and MichaelMitchell-at