isNonUndefined()
isNonUndefined<
T>(value):value is T
Checks if a value is not undefined.
note
Only checks undefined, not null. Use isNonNullable to check both.
Type Parametersβ
T: Tβ
The defined type.
Parametersβ
value: T | undefinedβ
The value to check.
Returns: value is Tβ
true if the value is not undefined, false otherwise.
See Alsoβ
Sinceβ
1.0.0
Exampleβ
isNonUndefined('hello'); // => true
isNonUndefined(0); // => true
isNonUndefined(null); // => true (only checks undefined)
isNonUndefined(undefined); // => false
How it works?β
Type guard that checks if a value is not undefined.
Type Narrowingβ
Common Checksβ
| Value | Result |
|---|---|
null | true |
0 | true |
'' | true |
false | true |
undefined | false |
vs isNonNullableβ
Use Casesβ
Verify definition πβ
Strictly check that a value is not undefined (allows null).
Useful for checking if a parameter was provided, even if it's null.
if (isNonUndefined(param)) {
// param was passed (could be null)
}
true
false