-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixed incompatible property error reporting in hasExcessProperties
under exactOptionalPropertyTypes
#60716
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
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:fix/error-report-prop-in-has-excess-properties
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fixed incompatible property error reporting in hasExcessProperties
under exactOptionalPropertyTypes
#60716
Changes from all commits
Commits
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
59 changes: 59 additions & 0 deletions
59
...lines/reference/incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.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,59 @@ | ||
incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts(5,3): error TS2322: Type 'number' is not assignable to type 'never'. | ||
incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts(10,7): error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'T2'. | ||
Types of property 'b' are incompatible. | ||
Type 'number' is not assignable to type 'never'. | ||
incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts(21,7): error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'T1'. | ||
Types of property 'b' are incompatible. | ||
Type 'number' is not assignable to type 'never'. | ||
incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts(28,7): error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'T2'. | ||
Type '{ a: number; b: number; }' is not assignable to type '{ a: number; b?: never; }'. | ||
Types of property 'b' are incompatible. | ||
Type 'number' is not assignable to type 'never'. | ||
|
||
|
||
==== incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts (4 errors) ==== | ||
type T1 = { a: number; b?: never }; | ||
|
||
const t1: T1 = { | ||
a: 0, | ||
b: 0, | ||
~ | ||
!!! error TS2322: Type 'number' is not assignable to type 'never'. | ||
!!! related TS6500 incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts:1:24: The expected type comes from property 'b' which is declared here on type 'T1' | ||
}; | ||
|
||
type T2 = { a: number; b?: never } | { a?: never; b: number }; | ||
|
||
const t2: T2 = { | ||
~~ | ||
!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'T2'. | ||
!!! error TS2322: Types of property 'b' are incompatible. | ||
!!! error TS2322: Type 'number' is not assignable to type 'never'. | ||
a: 0, | ||
b: 0, | ||
}; | ||
|
||
// for comparison with the above: | ||
const obj1 = { | ||
a: 0, | ||
b: 0, | ||
} | ||
|
||
const t3: T1 = obj1; | ||
~~ | ||
!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'T1'. | ||
!!! error TS2322: Types of property 'b' are incompatible. | ||
!!! error TS2322: Type 'number' is not assignable to type 'never'. | ||
|
||
const obj2 = { | ||
a: 0, | ||
b: 0, | ||
}; | ||
|
||
const t4: T2 = obj2; | ||
~~ | ||
!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'T2'. | ||
!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type '{ a: number; b?: never; }'. | ||
!!! error TS2322: Types of property 'b' are incompatible. | ||
!!! error TS2322: Type 'number' is not assignable to type 'never'. | ||
|
71 changes: 71 additions & 0 deletions
71
...aselines/reference/incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.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,71 @@ | ||
//// [tests/cases/compiler/incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts] //// | ||
|
||
=== incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts === | ||
type T1 = { a: number; b?: never }; | ||
>T1 : Symbol(T1, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 0, 0)) | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 0, 11)) | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 0, 22)) | ||
|
||
const t1: T1 = { | ||
>t1 : Symbol(t1, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 2, 5)) | ||
>T1 : Symbol(T1, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 0, 0)) | ||
|
||
a: 0, | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 2, 16)) | ||
|
||
b: 0, | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 3, 7)) | ||
|
||
}; | ||
|
||
type T2 = { a: number; b?: never } | { a?: never; b: number }; | ||
>T2 : Symbol(T2, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 5, 2)) | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 7, 11)) | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 7, 22)) | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 7, 38)) | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 7, 49)) | ||
|
||
const t2: T2 = { | ||
>t2 : Symbol(t2, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 9, 5)) | ||
>T2 : Symbol(T2, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 5, 2)) | ||
|
||
a: 0, | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 9, 16)) | ||
|
||
b: 0, | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 10, 7)) | ||
|
||
}; | ||
|
||
// for comparison with the above: | ||
const obj1 = { | ||
>obj1 : Symbol(obj1, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 15, 5)) | ||
|
||
a: 0, | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 15, 14)) | ||
|
||
b: 0, | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 16, 7)) | ||
} | ||
|
||
const t3: T1 = obj1; | ||
>t3 : Symbol(t3, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 20, 5)) | ||
>T1 : Symbol(T1, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 0, 0)) | ||
>obj1 : Symbol(obj1, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 15, 5)) | ||
|
||
const obj2 = { | ||
>obj2 : Symbol(obj2, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 22, 5)) | ||
|
||
a: 0, | ||
>a : Symbol(a, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 22, 14)) | ||
|
||
b: 0, | ||
>b : Symbol(b, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 23, 7)) | ||
|
||
}; | ||
|
||
const t4: T2 = obj2; | ||
>t4 : Symbol(t4, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 27, 5)) | ||
>T2 : Symbol(T2, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 5, 2)) | ||
>obj2 : Symbol(obj2, Decl(incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts, 22, 5)) | ||
|
115 changes: 115 additions & 0 deletions
115
.../baselines/reference/incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.types
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,115 @@ | ||
//// [tests/cases/compiler/incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts] //// | ||
|
||
=== incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts === | ||
type T1 = { a: number; b?: never }; | ||
>T1 : T1 | ||
> : ^^ | ||
>a : number | ||
> : ^^^^^^ | ||
>b : undefined | ||
> : ^^^^^^^^^ | ||
|
||
const t1: T1 = { | ||
>t1 : T1 | ||
> : ^^ | ||
>{ a: 0, b: 0,} : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
a: 0, | ||
>a : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
b: 0, | ||
>b : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
}; | ||
|
||
type T2 = { a: number; b?: never } | { a?: never; b: number }; | ||
>T2 : T2 | ||
> : ^^ | ||
>a : number | ||
> : ^^^^^^ | ||
>b : undefined | ||
> : ^^^^^^^^^ | ||
>a : undefined | ||
> : ^^^^^^^^^ | ||
>b : number | ||
> : ^^^^^^ | ||
|
||
const t2: T2 = { | ||
>t2 : T2 | ||
> : ^^ | ||
>{ a: 0, b: 0,} : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
a: 0, | ||
>a : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
b: 0, | ||
>b : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
}; | ||
|
||
// for comparison with the above: | ||
const obj1 = { | ||
>obj1 : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>{ a: 0, b: 0,} : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
a: 0, | ||
>a : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
b: 0, | ||
>b : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
} | ||
|
||
const t3: T1 = obj1; | ||
>t3 : T1 | ||
> : ^^ | ||
>obj1 : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
const obj2 = { | ||
>obj2 : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
>{ a: 0, b: 0,} : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
a: 0, | ||
>a : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
b: 0, | ||
>b : number | ||
> : ^^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
|
||
}; | ||
|
||
const t4: T2 = obj2; | ||
>t4 : T2 | ||
> : ^^ | ||
>obj2 : { a: number; b: number; } | ||
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
32 changes: 32 additions & 0 deletions
32
tests/cases/compiler/incompatiblePropertyErrorObjLiteralExactOptionalPropertyTypes1.ts
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,32 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
// @exactOptionalPropertyTypes: true | ||
|
||
type T1 = { a: number; b?: never }; | ||
|
||
const t1: T1 = { | ||
a: 0, | ||
b: 0, | ||
}; | ||
|
||
type T2 = { a: number; b?: never } | { a?: never; b: number }; | ||
|
||
const t2: T2 = { | ||
a: 0, | ||
b: 0, | ||
}; | ||
|
||
// for comparison with the above: | ||
const obj1 = { | ||
a: 0, | ||
b: 0, | ||
} | ||
|
||
const t3: T1 = obj1; | ||
|
||
const obj2 = { | ||
a: 0, | ||
b: 0, | ||
}; | ||
|
||
const t4: T2 = obj2; |
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.
I'm not particularly sure about this change but tests are unaffected