-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Elaborate on types in unions with the most overlap in properties #27087
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5ab8bd8
Try to find object/intersection types with the most overlap when fail…
DanielRosenwasser 76e721f
Added tests.
DanielRosenwasser 91af958
Accepted baselines.
DanielRosenwasser 6ae288f
Merge remote-tracking branch 'origin/master' into overlappyTypes
DanielRosenwasser b7da98b
Use intersection of member names to find largest overlap.
DanielRosenwasser 5a4378e
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
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
56 changes: 56 additions & 0 deletions
56
tests/baselines/reference/errorsOnUnionsOfOverlappingObjects01.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,56 @@ | ||
tests/cases/compiler/errorsOnUnionsOfOverlappingObjects01.ts(18,3): error TS2345: Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Foo | Other'. | ||
Type '{ a: string; b: string; }' is not assignable to type 'Foo'. | ||
Types of property 'b' are incompatible. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/compiler/errorsOnUnionsOfOverlappingObjects01.ts(19,3): error TS2345: Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Foo | Other'. | ||
Type '{ a: string; b: string; }' is not assignable to type 'Foo'. | ||
Types of property 'b' are incompatible. | ||
Type 'string' is not assignable to type 'number'. | ||
tests/cases/compiler/errorsOnUnionsOfOverlappingObjects01.ts(24,5): error TS2345: Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Bar | Other'. | ||
Object literal may only specify known properties, and 'a' does not exist in type 'Bar | Other'. | ||
|
||
|
||
==== tests/cases/compiler/errorsOnUnionsOfOverlappingObjects01.ts (3 errors) ==== | ||
interface Foo { | ||
a: string; | ||
b: number; | ||
}; | ||
|
||
interface Bar { | ||
b: string; | ||
} | ||
|
||
interface Other { | ||
totallyUnrelatedProperty: number; | ||
} | ||
|
||
export let x = { a: '', b: '' }; | ||
|
||
declare function f(x: Foo | Other): any; | ||
|
||
f(x); | ||
~ | ||
!!! error TS2345: Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Foo | Other'. | ||
!!! error TS2345: Type '{ a: string; b: string; }' is not assignable to type 'Foo'. | ||
!!! error TS2345: Types of property 'b' are incompatible. | ||
!!! error TS2345: Type 'string' is not assignable to type 'number'. | ||
f({ a: '', b: '' }) | ||
~~~~~~~~~~~~~~~~ | ||
!!! error TS2345: Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Foo | Other'. | ||
!!! error TS2345: Type '{ a: string; b: string; }' is not assignable to type 'Foo'. | ||
!!! error TS2345: Types of property 'b' are incompatible. | ||
!!! error TS2345: Type 'string' is not assignable to type 'number'. | ||
|
||
declare function g(x: Bar | Other): any; | ||
|
||
g(x); | ||
g({ a: '', b: '' }) | ||
~~~~~ | ||
!!! error TS2345: Argument of type '{ a: string; b: string; }' is not assignable to parameter of type 'Bar | Other'. | ||
!!! error TS2345: Object literal may only specify known properties, and 'a' does not exist in type 'Bar | Other'. | ||
|
||
declare function h(x: Foo | Bar | Other): any; | ||
|
||
h(x); | ||
h({ a: '', b: '' }) | ||
|
43 changes: 43 additions & 0 deletions
43
tests/baselines/reference/errorsOnUnionsOfOverlappingObjects01.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,43 @@ | ||
//// [errorsOnUnionsOfOverlappingObjects01.ts] | ||
interface Foo { | ||
a: string; | ||
b: number; | ||
}; | ||
|
||
interface Bar { | ||
b: string; | ||
} | ||
|
||
interface Other { | ||
totallyUnrelatedProperty: number; | ||
} | ||
|
||
export let x = { a: '', b: '' }; | ||
|
||
declare function f(x: Foo | Other): any; | ||
|
||
f(x); | ||
f({ a: '', b: '' }) | ||
|
||
declare function g(x: Bar | Other): any; | ||
|
||
g(x); | ||
g({ a: '', b: '' }) | ||
|
||
declare function h(x: Foo | Bar | Other): any; | ||
|
||
h(x); | ||
h({ a: '', b: '' }) | ||
|
||
|
||
//// [errorsOnUnionsOfOverlappingObjects01.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
; | ||
exports.x = { a: '', b: '' }; | ||
f(exports.x); | ||
f({ a: '', b: '' }); | ||
g(exports.x); | ||
g({ a: '', b: '' }); | ||
h(exports.x); | ||
h({ a: '', b: '' }); |
77 changes: 77 additions & 0 deletions
77
tests/baselines/reference/errorsOnUnionsOfOverlappingObjects01.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,77 @@ | ||
=== tests/cases/compiler/errorsOnUnionsOfOverlappingObjects01.ts === | ||
interface Foo { | ||
>Foo : Symbol(Foo, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 0, 0)) | ||
|
||
a: string; | ||
>a : Symbol(Foo.a, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 0, 15)) | ||
|
||
b: number; | ||
>b : Symbol(Foo.b, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 1, 14)) | ||
|
||
}; | ||
|
||
interface Bar { | ||
>Bar : Symbol(Bar, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 3, 2)) | ||
|
||
b: string; | ||
>b : Symbol(Bar.b, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 5, 15)) | ||
} | ||
|
||
interface Other { | ||
>Other : Symbol(Other, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 7, 1)) | ||
|
||
totallyUnrelatedProperty: number; | ||
>totallyUnrelatedProperty : Symbol(Other.totallyUnrelatedProperty, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 9, 17)) | ||
} | ||
|
||
export let x = { a: '', b: '' }; | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 10)) | ||
>a : Symbol(a, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 16)) | ||
>b : Symbol(b, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 23)) | ||
|
||
declare function f(x: Foo | Other): any; | ||
>f : Symbol(f, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 32)) | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 15, 19)) | ||
>Foo : Symbol(Foo, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 0, 0)) | ||
>Other : Symbol(Other, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 7, 1)) | ||
|
||
f(x); | ||
>f : Symbol(f, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 32)) | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 10)) | ||
|
||
f({ a: '', b: '' }) | ||
>f : Symbol(f, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 32)) | ||
>a : Symbol(a, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 18, 3)) | ||
>b : Symbol(b, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 18, 10)) | ||
|
||
declare function g(x: Bar | Other): any; | ||
>g : Symbol(g, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 18, 19)) | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 20, 19)) | ||
>Bar : Symbol(Bar, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 3, 2)) | ||
>Other : Symbol(Other, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 7, 1)) | ||
|
||
g(x); | ||
>g : Symbol(g, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 18, 19)) | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 10)) | ||
|
||
g({ a: '', b: '' }) | ||
>g : Symbol(g, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 18, 19)) | ||
>a : Symbol(a, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 23, 3)) | ||
>b : Symbol(b, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 23, 10)) | ||
|
||
declare function h(x: Foo | Bar | Other): any; | ||
>h : Symbol(h, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 23, 19)) | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 25, 19)) | ||
>Foo : Symbol(Foo, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 0, 0)) | ||
>Bar : Symbol(Bar, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 3, 2)) | ||
>Other : Symbol(Other, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 7, 1)) | ||
|
||
h(x); | ||
>h : Symbol(h, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 23, 19)) | ||
>x : Symbol(x, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 13, 10)) | ||
|
||
h({ a: '', b: '' }) | ||
>h : Symbol(h, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 23, 19)) | ||
>a : Symbol(a, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 28, 3)) | ||
>b : Symbol(b, Decl(errorsOnUnionsOfOverlappingObjects01.ts, 28, 10)) | ||
|
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.
Regression :(
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.
It's probably better this way, for now, until the element -> argument case has a special handler & diagnostic.