Skip to content

Unnecessary elaboration about not being assignable to type parameters #42849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue Feb 17, 2021 · 1 comment · Fixed by #42952
Closed

Unnecessary elaboration about not being assignable to type parameters #42849

DanielRosenwasser opened this issue Feb 17, 2021 · 1 comment · Fixed by #42952
Labels
Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@DanielRosenwasser
Copy link
Member

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'.
@DanielRosenwasser DanielRosenwasser changed the title Unnecessary repetition about constraint types Unnecessary elaboration about not being assignable to type parameters Feb 17, 2021
@RyanCavanaugh RyanCavanaugh added Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript labels Feb 18, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 18, 2021
@jonhue
Copy link
Contributor

jonhue commented Feb 25, 2021

I created a pull request that makes the proposed change (#42952) but had one small question about the behavior in scenarios related to the one discussed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Error Messages The issue relates to error messaging Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants