Skip to content

Unnecessary elaboration about not being assignable to type parameters #42849

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
async function foo<T>(x: T): Promise<T> {
  let yaddable = await getXOrYadda(x);
  return yaddable;
}

interface Yadda {
  stuff: string,
  things: string,
}

declare function getXOrYadda<T>(x: T): T | Yadda;

Here, you'll get an error like

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

Proposed

Either

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

or

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions