Skip to content

Failure to refine generic argument of type extends boolean #41333

Closed
@0rvar

Description

@0rvar

TypeScript Version: 4.0, nightly

Search Terms:
Generic, refinement, refine, extends boolean

Code

function foo<TValue extends boolean>(value: TValue) {
  if (value === true) {
    const truthy: true = value
  }
}

Expected behavior:
TValue should be refined to true. At the very least, the value variable should.

Actual behavior:
Error:

Type 'TValue' is not assignable to type 'true'.
  Type 'boolean' is not assignable to type 'true'.(2322)

Playground Link:
https://www.typescriptlang.org/play?ts=4.1.0-dev.20201030#code/GYVwdgxgLglg9mABMOcA8AVAagQwDYgCmihAHlIWACYDOiARqnoTmAHwAUAbvkQFyJsvQgEpEAbwCwAKESIYwRN2GIAvOsRQATkTFTZcxBAQ0omnVAAWATwHaiaxDwKEZcgL4zP0oA

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