Skip to content

Incorrect type inference #31741

Closed
Closed
@uqee

Description

@uqee

TypeScript Version: 3.3.3333

Search Terms:
typescript type guard else never

Code

    enum Type { N, S }

    interface Interface<E extends Type | unknown = unknown> {
      type?: Type
      data?: // just for an idea of how the E parameter is used
        E extends Type.N ? number :
        E extends Type.S ? string :
        number | string
    }

    const isN = (i: Interface): i is Interface<Type.N> => i.type === Type.N

    const i: Interface<unknown> = {}

    if (isN(i)) {
      // i is Interface<Type.N>
    } else {
      // i is never
      // shouldn't it stay Interface<unknown>?
      i
    }

Related Issues:
#17789
#10934

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions