-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingHelp WantedYou can do thisYou can do this
Milestone
Description
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.
JoshuaCWebDeveloper
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingThe issue relates to error messagingHelp WantedYou can do thisYou can do this