Skip to content
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

Improve error message for stricter types not matching generic T extends SomeInterface #31739

Closed
5 tasks done
patrys opened this issue Jun 3, 2019 · 1 comment
Closed
5 tasks done

Comments

@patrys
Copy link

patrys commented Jun 3, 2019

Search Terms

generic type is not assignable to type error

Suggestion

It's impossible for a non-generic type to be assignable to a generic that extends an interface. This is understandable as at the time of type checking it's impossible to determine the generic type's fields. It would be nice if the error message explained that instead of just saying that the types are incompatible.

Use Cases

See the example below:

Examples

interface Foo {
    bar: string;
}

function baz<T extends Foo> {
    const fizz: T = { bar: "hello world " };
}

Current error:

Type '{ bar: string; }' is not assignable to type 'T'.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@jack-williams
Copy link
Collaborator

This is fixed by #30394

@patrys patrys closed this as completed Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants