Converts a type into a tuple that is optional when T is void or undefined.
T
void
undefined
Designed for use with rest parameters in generic functions, allowing callers to omit the argument entirely when the type indicates no value is expected.
The type to evaluate for optionality.
function dispatch<T>(action: string, ...payload: OptionalIfVoid<T>): void { // ...}dispatch<void>('reset'); // ✓ OK — payload omitteddispatch<number>('increment', 5); // ✓ OK — payload requireddispatch<number>('increment'); // ✗ Error — missing argument Copy
function dispatch<T>(action: string, ...payload: OptionalIfVoid<T>): void { // ...}dispatch<void>('reset'); // ✓ OK — payload omitteddispatch<number>('increment', 5); // ✓ OK — payload requireddispatch<number>('increment'); // ✗ Error — missing argument
Converts a type into a tuple that is optional when
Tisvoidorundefined.Designed for use with rest parameters in generic functions, allowing callers to omit the argument entirely when the type indicates no value is expected.