isNonUndefined()
isNonUndefined<
T>(value):value is T
Checks if a value is not undefined.
remarque
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