Skip to content

Don't mention constraints in errors when type parameters don't explicitly specify them #33436

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
function f<T>(x: T) {
    x = {};
}

Current

Type '{}' is not assignable to type 'T'.
  '{}' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.

Type '10' is not assignable to type 'T'.
  '10' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'.

Nobody ever mentioned a constraint or {} in this code, so why is it being displayed? As a user, this is telling me more than I needed or wanted to know.

Proposed

Type '{}' is not assignable to type 'T'.
  'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.


Type '10' is not assignable to type 'T'.
  'T' could be instantiated with an arbitrary type which could be unrelated to '10'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions