Repository navigation
Improved errors using type reference targets #25115
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
Merged
Daniel Rosenwasser (DanielRosenwasser)
merged 6 commits into
master
from
matchingTypeRefs
Jun 21, 2018
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
639d9eb
Added test.
DanielRosenwasser 9ba2eff
Accepted baselines.
DanielRosenwasser 4f32691
Try to report errors on types who have matching type references.
DanielRosenwasser 33b1e3a
Accepted baselines.
DanielRosenwasser 9df95fe
Expand better error messages to anonymous object types with identical…
DanielRosenwasser 6d755aa
Accepted baselines.
DanielRosenwasser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests/baselines/reference/unionTypeErrorMessageTypeRefs01.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(25,1): error TS2322: Type 'A<Foo>' is not assignable to type 'A<Bar> | B<Baz> | C<Kwah>'. | ||
| Type 'A<Foo>' is not assignable to type 'A<Bar>'. | ||
| Type 'Foo' is not assignable to type 'Bar'. | ||
| Property 'bar' is missing in type 'Foo'. | ||
| tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(26,1): error TS2322: Type 'B<Foo>' is not assignable to type 'A<Bar> | B<Baz> | C<Kwah>'. | ||
| Type 'B<Foo>' is not assignable to type 'B<Baz>'. | ||
| Type 'Foo' is not assignable to type 'Baz'. | ||
| Property 'baz' is missing in type 'Foo'. | ||
| tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(27,1): error TS2322: Type 'C<Foo>' is not assignable to type 'A<Bar> | B<Baz> | C<Kwah>'. | ||
| Type 'C<Foo>' is not assignable to type 'C<Kwah>'. | ||
| Type 'Foo' is not assignable to type 'Kwah'. | ||
| Property 'kwah' is missing in type 'Foo'. | ||
| tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(48,1): error TS2322: Type 'X<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'. | ||
| Type 'X<Foo>' is not assignable to type 'X<Bar>'. | ||
| Types of property 'xProp' are incompatible. | ||
| Type 'Foo' is not assignable to type 'Bar'. | ||
| tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(49,1): error TS2322: Type 'Y<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'. | ||
| Type 'Y<Foo>' is not assignable to type 'Y<Baz>'. | ||
| Types of property 'yProp' are incompatible. | ||
| Type 'Foo' is not assignable to type 'Baz'. | ||
| tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts(50,1): error TS2322: Type 'Z<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'. | ||
| Type 'Z<Foo>' is not assignable to type 'Z<Kwah>'. | ||
| Types of property 'zProp' are incompatible. | ||
| Type 'Foo' is not assignable to type 'Kwah'. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts (6 errors) ==== | ||
| interface Foo { foo: any } | ||
| interface Bar { bar: any } | ||
| interface Baz { baz: any } | ||
| interface Kwah { kwah: any } | ||
|
|
||
| //////// | ||
|
|
||
| interface A<T> { | ||
| aProp: T; | ||
| } | ||
|
|
||
| interface B<T> { | ||
| bProp: T; | ||
| } | ||
|
|
||
| interface C<T> { | ||
| cProp: T; | ||
| } | ||
|
|
||
| declare const a: A<Foo>; | ||
| declare const b: B<Foo>; | ||
| declare const c: C<Foo>; | ||
| declare let thingOfInterfaces: A<Bar> | B<Baz> | C<Kwah>; | ||
|
|
||
| thingOfInterfaces = a; | ||
| ~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2322: Type 'A<Foo>' is not assignable to type 'A<Bar> | B<Baz> | C<Kwah>'. | ||
| !!! error TS2322: Type 'A<Foo>' is not assignable to type 'A<Bar>'. | ||
| !!! error TS2322: Type 'Foo' is not assignable to type 'Bar'. | ||
| !!! error TS2322: Property 'bar' is missing in type 'Foo'. | ||
| thingOfInterfaces = b; | ||
| ~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2322: Type 'B<Foo>' is not assignable to type 'A<Bar> | B<Baz> | C<Kwah>'. | ||
| !!! error TS2322: Type 'B<Foo>' is not assignable to type 'B<Baz>'. | ||
| !!! error TS2322: Type 'Foo' is not assignable to type 'Baz'. | ||
| !!! error TS2322: Property 'baz' is missing in type 'Foo'. | ||
| thingOfInterfaces = c; | ||
| ~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2322: Type 'C<Foo>' is not assignable to type 'A<Bar> | B<Baz> | C<Kwah>'. | ||
| !!! error TS2322: Type 'C<Foo>' is not assignable to type 'C<Kwah>'. | ||
| !!! error TS2322: Type 'Foo' is not assignable to type 'Kwah'. | ||
| !!! error TS2322: Property 'kwah' is missing in type 'Foo'. | ||
|
|
||
| //////// | ||
|
|
||
| type X<T> = { | ||
| xProp: T; | ||
| } | ||
|
|
||
| type Y<T> = { | ||
| yProp: T; | ||
| } | ||
|
|
||
| type Z<T> = { | ||
| zProp: T; | ||
| } | ||
|
|
||
| declare const x: X<Foo>; | ||
| declare const y: Y<Foo>; | ||
| declare const z: Z<Foo>; | ||
| declare let thingOfTypeAliases: X<Bar> | Y<Baz> | Z<Kwah>; | ||
|
|
||
| thingOfTypeAliases = x; | ||
| ~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2322: Type 'X<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'. | ||
| !!! error TS2322: Type 'X<Foo>' is not assignable to type 'X<Bar>'. | ||
| !!! error TS2322: Types of property 'xProp' are incompatible. | ||
| !!! error TS2322: Type 'Foo' is not assignable to type 'Bar'. | ||
| thingOfTypeAliases = y; | ||
| ~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2322: Type 'Y<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'. | ||
| !!! error TS2322: Type 'Y<Foo>' is not assignable to type 'Y<Baz>'. | ||
| !!! error TS2322: Types of property 'yProp' are incompatible. | ||
| !!! error TS2322: Type 'Foo' is not assignable to type 'Baz'. | ||
| thingOfTypeAliases = z; | ||
| ~~~~~~~~~~~~~~~~~~ | ||
| !!! error TS2322: Type 'Z<Foo>' is not assignable to type 'X<Bar> | Y<Baz> | Z<Kwah>'. | ||
| !!! error TS2322: Type 'Z<Foo>' is not assignable to type 'Z<Kwah>'. | ||
| !!! error TS2322: Types of property 'zProp' are incompatible. | ||
| !!! error TS2322: Type 'Foo' is not assignable to type 'Kwah'. |
59 changes: 59 additions & 0 deletions
59
tests/baselines/reference/unionTypeErrorMessageTypeRefs01.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| //// [unionTypeErrorMessageTypeRefs01.ts] | ||
| interface Foo { foo: any } | ||
| interface Bar { bar: any } | ||
| interface Baz { baz: any } | ||
| interface Kwah { kwah: any } | ||
|
|
||
| //////// | ||
|
|
||
| interface A<T> { | ||
| aProp: T; | ||
| } | ||
|
|
||
| interface B<T> { | ||
| bProp: T; | ||
| } | ||
|
|
||
| interface C<T> { | ||
| cProp: T; | ||
| } | ||
|
|
||
| declare const a: A<Foo>; | ||
| declare const b: B<Foo>; | ||
| declare const c: C<Foo>; | ||
| declare let thingOfInterfaces: A<Bar> | B<Baz> | C<Kwah>; | ||
|
|
||
| thingOfInterfaces = a; | ||
| thingOfInterfaces = b; | ||
| thingOfInterfaces = c; | ||
|
|
||
| //////// | ||
|
|
||
| type X<T> = { | ||
| xProp: T; | ||
| } | ||
|
|
||
| type Y<T> = { | ||
| yProp: T; | ||
| } | ||
|
|
||
| type Z<T> = { | ||
| zProp: T; | ||
| } | ||
|
|
||
| declare const x: X<Foo>; | ||
| declare const y: Y<Foo>; | ||
| declare const z: Z<Foo>; | ||
| declare let thingOfTypeAliases: X<Bar> | Y<Baz> | Z<Kwah>; | ||
|
|
||
| thingOfTypeAliases = x; | ||
| thingOfTypeAliases = y; | ||
| thingOfTypeAliases = z; | ||
|
|
||
| //// [unionTypeErrorMessageTypeRefs01.js] | ||
| thingOfInterfaces = a; | ||
| thingOfInterfaces = b; | ||
| thingOfInterfaces = c; | ||
| thingOfTypeAliases = x; | ||
| thingOfTypeAliases = y; | ||
| thingOfTypeAliases = z; |
147 changes: 147 additions & 0 deletions
147
tests/baselines/reference/unionTypeErrorMessageTypeRefs01.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| === tests/cases/compiler/unionTypeErrorMessageTypeRefs01.ts === | ||
| interface Foo { foo: any } | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
| >foo : Symbol(Foo.foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 15)) | ||
|
|
||
| interface Bar { bar: any } | ||
| >Bar : Symbol(Bar, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 26)) | ||
| >bar : Symbol(Bar.bar, Decl(unionTypeErrorMessageTypeRefs01.ts, 1, 15)) | ||
|
|
||
| interface Baz { baz: any } | ||
| >Baz : Symbol(Baz, Decl(unionTypeErrorMessageTypeRefs01.ts, 1, 26)) | ||
| >baz : Symbol(Baz.baz, Decl(unionTypeErrorMessageTypeRefs01.ts, 2, 15)) | ||
|
|
||
| interface Kwah { kwah: any } | ||
| >Kwah : Symbol(Kwah, Decl(unionTypeErrorMessageTypeRefs01.ts, 2, 26)) | ||
| >kwah : Symbol(Kwah.kwah, Decl(unionTypeErrorMessageTypeRefs01.ts, 3, 16)) | ||
|
|
||
| //////// | ||
|
|
||
| interface A<T> { | ||
| >A : Symbol(A, Decl(unionTypeErrorMessageTypeRefs01.ts, 3, 28)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 7, 12)) | ||
|
|
||
| aProp: T; | ||
| >aProp : Symbol(A.aProp, Decl(unionTypeErrorMessageTypeRefs01.ts, 7, 16)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 7, 12)) | ||
| } | ||
|
|
||
| interface B<T> { | ||
| >B : Symbol(B, Decl(unionTypeErrorMessageTypeRefs01.ts, 9, 1)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 11, 12)) | ||
|
|
||
| bProp: T; | ||
| >bProp : Symbol(B.bProp, Decl(unionTypeErrorMessageTypeRefs01.ts, 11, 16)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 11, 12)) | ||
| } | ||
|
|
||
| interface C<T> { | ||
| >C : Symbol(C, Decl(unionTypeErrorMessageTypeRefs01.ts, 13, 1)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 15, 12)) | ||
|
|
||
| cProp: T; | ||
| >cProp : Symbol(C.cProp, Decl(unionTypeErrorMessageTypeRefs01.ts, 15, 16)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 15, 12)) | ||
| } | ||
|
|
||
| declare const a: A<Foo>; | ||
| >a : Symbol(a, Decl(unionTypeErrorMessageTypeRefs01.ts, 19, 13)) | ||
| >A : Symbol(A, Decl(unionTypeErrorMessageTypeRefs01.ts, 3, 28)) | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
|
|
||
| declare const b: B<Foo>; | ||
| >b : Symbol(b, Decl(unionTypeErrorMessageTypeRefs01.ts, 20, 13)) | ||
| >B : Symbol(B, Decl(unionTypeErrorMessageTypeRefs01.ts, 9, 1)) | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
|
|
||
| declare const c: C<Foo>; | ||
| >c : Symbol(c, Decl(unionTypeErrorMessageTypeRefs01.ts, 21, 13)) | ||
| >C : Symbol(C, Decl(unionTypeErrorMessageTypeRefs01.ts, 13, 1)) | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
|
|
||
| declare let thingOfInterfaces: A<Bar> | B<Baz> | C<Kwah>; | ||
| >thingOfInterfaces : Symbol(thingOfInterfaces, Decl(unionTypeErrorMessageTypeRefs01.ts, 22, 11)) | ||
| >A : Symbol(A, Decl(unionTypeErrorMessageTypeRefs01.ts, 3, 28)) | ||
| >Bar : Symbol(Bar, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 26)) | ||
| >B : Symbol(B, Decl(unionTypeErrorMessageTypeRefs01.ts, 9, 1)) | ||
| >Baz : Symbol(Baz, Decl(unionTypeErrorMessageTypeRefs01.ts, 1, 26)) | ||
| >C : Symbol(C, Decl(unionTypeErrorMessageTypeRefs01.ts, 13, 1)) | ||
| >Kwah : Symbol(Kwah, Decl(unionTypeErrorMessageTypeRefs01.ts, 2, 26)) | ||
|
|
||
| thingOfInterfaces = a; | ||
| >thingOfInterfaces : Symbol(thingOfInterfaces, Decl(unionTypeErrorMessageTypeRefs01.ts, 22, 11)) | ||
| >a : Symbol(a, Decl(unionTypeErrorMessageTypeRefs01.ts, 19, 13)) | ||
|
|
||
| thingOfInterfaces = b; | ||
| >thingOfInterfaces : Symbol(thingOfInterfaces, Decl(unionTypeErrorMessageTypeRefs01.ts, 22, 11)) | ||
| >b : Symbol(b, Decl(unionTypeErrorMessageTypeRefs01.ts, 20, 13)) | ||
|
|
||
| thingOfInterfaces = c; | ||
| >thingOfInterfaces : Symbol(thingOfInterfaces, Decl(unionTypeErrorMessageTypeRefs01.ts, 22, 11)) | ||
| >c : Symbol(c, Decl(unionTypeErrorMessageTypeRefs01.ts, 21, 13)) | ||
|
|
||
| //////// | ||
|
|
||
| type X<T> = { | ||
| >X : Symbol(X, Decl(unionTypeErrorMessageTypeRefs01.ts, 26, 22)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 30, 7)) | ||
|
|
||
| xProp: T; | ||
| >xProp : Symbol(xProp, Decl(unionTypeErrorMessageTypeRefs01.ts, 30, 13)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 30, 7)) | ||
| } | ||
|
|
||
| type Y<T> = { | ||
| >Y : Symbol(Y, Decl(unionTypeErrorMessageTypeRefs01.ts, 32, 1)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 34, 7)) | ||
|
|
||
| yProp: T; | ||
| >yProp : Symbol(yProp, Decl(unionTypeErrorMessageTypeRefs01.ts, 34, 13)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 34, 7)) | ||
| } | ||
|
|
||
| type Z<T> = { | ||
| >Z : Symbol(Z, Decl(unionTypeErrorMessageTypeRefs01.ts, 36, 1)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 38, 7)) | ||
|
|
||
| zProp: T; | ||
| >zProp : Symbol(zProp, Decl(unionTypeErrorMessageTypeRefs01.ts, 38, 13)) | ||
| >T : Symbol(T, Decl(unionTypeErrorMessageTypeRefs01.ts, 38, 7)) | ||
| } | ||
|
|
||
| declare const x: X<Foo>; | ||
| >x : Symbol(x, Decl(unionTypeErrorMessageTypeRefs01.ts, 42, 13)) | ||
| >X : Symbol(X, Decl(unionTypeErrorMessageTypeRefs01.ts, 26, 22)) | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
|
|
||
| declare const y: Y<Foo>; | ||
| >y : Symbol(y, Decl(unionTypeErrorMessageTypeRefs01.ts, 43, 13)) | ||
| >Y : Symbol(Y, Decl(unionTypeErrorMessageTypeRefs01.ts, 32, 1)) | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
|
|
||
| declare const z: Z<Foo>; | ||
| >z : Symbol(z, Decl(unionTypeErrorMessageTypeRefs01.ts, 44, 13)) | ||
| >Z : Symbol(Z, Decl(unionTypeErrorMessageTypeRefs01.ts, 36, 1)) | ||
| >Foo : Symbol(Foo, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 0)) | ||
|
|
||
| declare let thingOfTypeAliases: X<Bar> | Y<Baz> | Z<Kwah>; | ||
| >thingOfTypeAliases : Symbol(thingOfTypeAliases, Decl(unionTypeErrorMessageTypeRefs01.ts, 45, 11)) | ||
| >X : Symbol(X, Decl(unionTypeErrorMessageTypeRefs01.ts, 26, 22)) | ||
| >Bar : Symbol(Bar, Decl(unionTypeErrorMessageTypeRefs01.ts, 0, 26)) | ||
| >Y : Symbol(Y, Decl(unionTypeErrorMessageTypeRefs01.ts, 32, 1)) | ||
| >Baz : Symbol(Baz, Decl(unionTypeErrorMessageTypeRefs01.ts, 1, 26)) | ||
| >Z : Symbol(Z, Decl(unionTypeErrorMessageTypeRefs01.ts, 36, 1)) | ||
| >Kwah : Symbol(Kwah, Decl(unionTypeErrorMessageTypeRefs01.ts, 2, 26)) | ||
|
|
||
| thingOfTypeAliases = x; | ||
| >thingOfTypeAliases : Symbol(thingOfTypeAliases, Decl(unionTypeErrorMessageTypeRefs01.ts, 45, 11)) | ||
| >x : Symbol(x, Decl(unionTypeErrorMessageTypeRefs01.ts, 42, 13)) | ||
|
|
||
| thingOfTypeAliases = y; | ||
| >thingOfTypeAliases : Symbol(thingOfTypeAliases, Decl(unionTypeErrorMessageTypeRefs01.ts, 45, 11)) | ||
| >y : Symbol(y, Decl(unionTypeErrorMessageTypeRefs01.ts, 43, 13)) | ||
|
|
||
| thingOfTypeAliases = z; | ||
| >thingOfTypeAliases : Symbol(thingOfTypeAliases, Decl(unionTypeErrorMessageTypeRefs01.ts, 45, 11)) | ||
| >z : Symbol(z, Decl(unionTypeErrorMessageTypeRefs01.ts, 44, 13)) | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
getObjectFlagsinstead of(source as ObjectType).objectFlags