Skip to content

Generic conditional type T extends never ? 'yes' : 'no' resolves to never when T is never. #31751

Closed
@rickwebiii

Description

@rickwebiii

TypeScript Version: 3.6.0-dev.20190603

Search Terms:
never, extends, generic, conditional type
Code

type MakesSense = never extends never ? 'yes' : 'no' // Resolves to 'yes'

type ExtendsNever<T> = T extends never ? 'yes' : 'no'

type MakesSenseToo = ExtendsNever<{}> // Resolves to 'no'
type Huh = ExtendsNever<never> // Expect to resolve to 'yes', actually resolves to never 

Expected behavior:
Huh should resolve to 'yes', as MakesSense does.

Actual behavior:
Huh resolves to never.

For another variant, you can change ExtendsNever to

type ExtendsNever<T extends never> = T extends never ? 'yes' : 'no'

and ExtendsNever still resolves to never.

Playground Link:
Here

Related Issues:
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions