Skip to content

Could be instantiated with a different subtype of constraintΒ #50027

Closed
@quantumsheep

Description

@quantumsheep

Bug Report

πŸ”Ž Search Terms

not assignable to the constraint of type
could be instantiated with a different subtype of constraint

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type A = () => void;
type B = () => void;

// error
function f1<T extends A | B>(value: T): T {
  return () => value();
}

// ok
function f2<T extends A | B>(value: T): T extends A ? A : B {
  return () => value();
}

πŸ™ Actual behavior

The following error is happening with f1 but not f2:

Type '() => void' is not assignable to type 'T'.
  '() => void' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'B | A'.

πŸ™‚ Expected behavior

Defining f1 should work fine.

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