Skip to content

tyneq


tyneq / Assume

Type Alias: Assume<T, U>

Assume<T, U> = T extends U ? T : U

Defined in: src/types/utility.ts:71

Narrows T to U if T extends U; otherwise falls back to U.

Type Parameters

Type Parameter
T
U

Remarks

Use this when you have a type variable T that you know satisfies U in context but TypeScript cannot prove it statically. Assume<T, U> resolves to T when the constraint holds and to U as a safe fallback when it does not - avoiding any.

Example

ts
// Generic return type constrained to the concrete key type:
type ValueAt<T, K extends keyof T> = Assume<T[K], string>;
// T[K] is string -> resolves to T[K] (the specific type is kept)
// T[K] is number -> resolves to string (falls back to the bound)