Skip to content

feat: implement IsInhabited as a first-class type primitive #49

Description

@martyy-code

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

  • IsInhabited<T> implemented in src/types/
  • check<T>().isInhabited() chainable API
  • toBeInhabited() Vitest matcher
  • Tests: IsInhabited<string> → true, IsInhabited<never> → false
  • Integration with existing Inhabited if already present

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typesType utilities (Equal, IsAny, IsNever, ...)enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions