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