Home

orundefined

Orundefined is a term used in type systems to describe a value that may be either a specific type or undefined. It is a way to model optional data, where the absence of a value is represented by the special value undefined rather than a separate null value.

In TypeScript and related typing ecosystems, orundefined is typically expressed as a union with undefined. The

Usage examples include function return types, variables, and object properties that may be omitted. For instance,

Orundefined is distinct from null in languages where both concepts exist; undefined typically signals the absence

See also: Optional types, Union types, Undefined, Null, TypeScript type aliases.

standard
form
is
T
|
undefined,
meaning
a
value
is
either
of
type
T
or
not
provided
at
all.
Some
codebases
adopt
a
named
alias
for
readability,
such
as
type
OrUndefined<T>
=
T
|
undefined.
This
alias
is
not
built
into
the
language
by
default
but
is
provided
by
libraries
like
type-fest
and
can
be
defined
in
user
code.
a
function
might
return
string
|
undefined
if
a
value
might
be
missing,
and
an
object
property
declared
as
property?:
string
has
the
effective
type
string
|
undefined.
When
using
orundefined,
developers
often
perform
type
narrowing
to
handle
the
undefined
case,
or
supply
default
values
to
coerce
to
a
defined
type.
of
a
value
rather
than
an
explicit
null
result.
Understanding
orundefined
helps
in
writing
robust
code
that
explicitly
accounts
for
optional
data
and
reduces
runtime
errors
related
to
undefined
values.