Skip to content

Assignability error reporting should have a more specific error for unions #6541

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

Open
sandersn opened this issue Jan 19, 2016 · 0 comments
Open
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Help Wanted You can do this
Milestone

Comments

@sandersn
Copy link
Member

interface A {
    a: number
}
interface B {
    b: number
}
interface C {
    c: number
}
interface D {
    d: number
}
declare var c: C;
let abc: ((A | B) & C) | D = c;

Actual error:

Type 'C' is not assignable to type '((A | B) & C) | D'.
  Type 'C' is not assignable to type 'D'.
    ....

Expected error:

Type 'C' is not assignable to any branch of the union type '((A | B) & C) | D'.
  For example, type 'C' is not assignable to type 'D'.
    ....

Error reporting on unions doesn't mention that the compiler tried to assign the source to all branches of the target. Instead it proceeds to elaborate just the last branch's error. It should make it clear that the error elaboration is just one of several checks that failed.

Otherwise it is easy to assume that the compiler only tried the last branch and somehow skipped the "more promising" branch (which ultimately also fails, but at least contains the source type).

Based on one of the multiple issues reported by @Aleksey-Bykov in #6538.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants