AssertNotNil
Since 1.3.0
Assert that type T is not never.
Signature
typescript
type AssertNotNil<T> = [T] extends [never] ? never : TParameters
| Parameter | Description |
|---|---|
T | The type to check |
Examples
Basic Usage
typescript
import type { AssertNotNil } from 'uni-types'
type Result = AssertNotNil<string> // string
type Failed = AssertNotNil<never> // neverWith Conditional Types
typescript
type MaybeString = string | undefined
type Validated = AssertNotNil<Exclude<MaybeString, undefined>> // stringWith Inferred Types
typescript
type ExtractArray<T> = T extends (infer E)[] ? E : never
type Result = AssertNotNil<ExtractArray<string[]>> // stringRelated
RequireNotNullish- Ensure type is not null or undefinedAssertExtends- Assert type extends another