Description
Implement as a first-class matcher. It returns true if T has at least one inhabiting value (i.e. is not never), and false otherwise.
This is the one primitive that neither expect-type nor tsd provides, and it addresses a real gap: testing that a type utility doesn't accidentally collapse everything to never.
Why
expect-type has IsNever but no inverse. IsInhabited is useful for:
- Validating that a mapped type produces non-empty results
- Testing that a conditional type doesn't collapse to
never
- Guarding against
Extract<T, never> patterns that silently return never
Acceptance criteria
Risks
- Low.
IsInhabited<T> is a straightforward boolean wrapper around [T] extends [never] ? false : true.
Related
src/types/special.ts for existing special-type patterns
Description
Implement as a first-class matcher. It returns
trueifThas at least one inhabiting value (i.e. is notnever), andfalseotherwise.This is the one primitive that neither
expect-typenortsdprovides, and it addresses a real gap: testing that a type utility doesn't accidentally collapse everything tonever.Why
expect-typehasIsNeverbut no inverse.IsInhabitedis useful for:neverExtract<T, never>patterns that silently returnneverAcceptance criteria
IsInhabited<T>implemented insrc/types/check<T>().isInhabited()chainable APItoBeInhabited()Vitest matcherIsInhabited<string>→ true,IsInhabited<never>→ falseInhabitedif already presentRisks
IsInhabited<T>is a straightforward boolean wrapper around[T] extends [never] ? false : true.Related
src/types/special.tsfor existing special-type patterns