Function: optional()
optional<
K,V>(key,value):Record<K,V> |undefined
{ [key]: value } when value is present, otherwise undefined - so an
absent optional field stays ABSENT when spread, rather than becoming an
explicit undefined that exactOptionalPropertyTypes rejects.
Spelling that inline costs a repeated, double-evaluated ternary per field
(...(v ? { key: v } : {})), which is how config resolvers end up computing
the same value twice.
Type Parameters
Section titled “Type Parameters”K extends string
V
Parameters
Section titled “Parameters”K
V | null | undefined
Returns
Section titled “Returns”Record<K, V> | undefined
Example
Section titled “Example”return { ...optional("appId", configuredAppId), ...optional("endpoint", config.endpoint),};