-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Fixed an issue with excess/ common property check errors being incorrectly reported when relating to targets with multiple index signatures #60869
Open
Andarist
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
Andarist:fix/extra-property-checks-vs-multiple-index-signatures
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
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 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
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/commonPropertyCheckWithMultipleIndexSignatures1.errors.txt
This file contains 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,57 @@ | ||
commonPropertyCheckWithMultipleIndexSignatures1.ts(21,8): error TS2353: Object literal may only specify known properties, and 'notCommon' does not exist in type 'ISubType'. | ||
commonPropertyCheckWithMultipleIndexSignatures1.ts(44,12): error TS2353: Object literal may only specify known properties, and 'notCommon' does not exist in type 'ISubType_2'. | ||
|
||
|
||
==== commonPropertyCheckWithMultipleIndexSignatures1.ts (2 errors) ==== | ||
interface ITopType { | ||
tKey?: string; | ||
} | ||
|
||
interface ISubType extends ITopType { | ||
sKey?: string; | ||
} | ||
|
||
interface ITestInteface { | ||
[pA: string]: ITopType; | ||
[pB: number]: ISubType; | ||
} | ||
|
||
const testObj1: ITestInteface = { | ||
a: { tKey: "tVal" }, | ||
1: { tKey: "tVal", sKey: "sVal" }, | ||
}; | ||
|
||
const testObj1_2: ITestInteface = { | ||
a: { tKey: "tVal" }, | ||
1: { notCommon: "val3" }, | ||
~~~~~~~~~ | ||
!!! error TS2353: Object literal may only specify known properties, and 'notCommon' does not exist in type 'ISubType'. | ||
!!! related TS6501 commonPropertyCheckWithMultipleIndexSignatures1.ts:11:3: The expected type comes from this index signature. | ||
}; | ||
|
||
interface ITopType_2 { | ||
tKey_2?: string; | ||
} | ||
|
||
interface ISubType_2 extends ITopType_2 { | ||
sKey_2?: string; | ||
} | ||
|
||
interface ITestInteface_2 { | ||
[pA_2: string]: ITopType_2; | ||
[pB_2: `sub_${string}`]: ISubType_2; | ||
} | ||
|
||
const testObj2: ITestInteface_2 = { | ||
a: { tKey_2: "tVal_2 " }, | ||
sub_b: { tKey_2: "tVal_2 ", sKey_2: "sVal_2" }, | ||
}; | ||
|
||
const testObj2_2: ITestInteface_2 = { | ||
a: { tKey_2: "tVal_2 " }, | ||
sub_b: { notCommon: "val3" }, | ||
~~~~~~~~~ | ||
!!! error TS2353: Object literal may only specify known properties, and 'notCommon' does not exist in type 'ISubType_2'. | ||
!!! related TS6501 commonPropertyCheckWithMultipleIndexSignatures1.ts:34:3: The expected type comes from this index signature. | ||
}; | ||
|
115 changes: 115 additions & 0 deletions
115
tests/baselines/reference/commonPropertyCheckWithMultipleIndexSignatures1.symbols
This file contains 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/commonPropertyCheckWithMultipleIndexSignatures1.ts] //// | ||
|
||
=== commonPropertyCheckWithMultipleIndexSignatures1.ts === | ||
interface ITopType { | ||
>ITopType : Symbol(ITopType, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 0, 0)) | ||
|
||
tKey?: string; | ||
>tKey : Symbol(ITopType.tKey, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 0, 20)) | ||
} | ||
|
||
interface ISubType extends ITopType { | ||
>ISubType : Symbol(ISubType, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 2, 1)) | ||
>ITopType : Symbol(ITopType, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 0, 0)) | ||
|
||
sKey?: string; | ||
>sKey : Symbol(ISubType.sKey, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 4, 37)) | ||
} | ||
|
||
interface ITestInteface { | ||
>ITestInteface : Symbol(ITestInteface, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 6, 1)) | ||
|
||
[pA: string]: ITopType; | ||
>pA : Symbol(pA, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 9, 3)) | ||
>ITopType : Symbol(ITopType, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 0, 0)) | ||
|
||
[pB: number]: ISubType; | ||
>pB : Symbol(pB, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 10, 3)) | ||
>ISubType : Symbol(ISubType, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 2, 1)) | ||
} | ||
|
||
const testObj1: ITestInteface = { | ||
>testObj1 : Symbol(testObj1, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 13, 5)) | ||
>ITestInteface : Symbol(ITestInteface, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 6, 1)) | ||
|
||
a: { tKey: "tVal" }, | ||
>a : Symbol(a, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 13, 33)) | ||
>tKey : Symbol(tKey, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 14, 6)) | ||
|
||
1: { tKey: "tVal", sKey: "sVal" }, | ||
>1 : Symbol(1, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 14, 22)) | ||
>tKey : Symbol(tKey, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 15, 6)) | ||
>sKey : Symbol(sKey, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 15, 20)) | ||
|
||
}; | ||
|
||
const testObj1_2: ITestInteface = { | ||
>testObj1_2 : Symbol(testObj1_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 18, 5)) | ||
>ITestInteface : Symbol(ITestInteface, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 6, 1)) | ||
|
||
a: { tKey: "tVal" }, | ||
>a : Symbol(a, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 18, 35)) | ||
>tKey : Symbol(tKey, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 19, 6)) | ||
|
||
1: { notCommon: "val3" }, | ||
>1 : Symbol(1, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 19, 22)) | ||
>notCommon : Symbol(notCommon, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 20, 6)) | ||
|
||
}; | ||
|
||
interface ITopType_2 { | ||
>ITopType_2 : Symbol(ITopType_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 21, 2)) | ||
|
||
tKey_2?: string; | ||
>tKey_2 : Symbol(ITopType_2.tKey_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 23, 22)) | ||
} | ||
|
||
interface ISubType_2 extends ITopType_2 { | ||
>ISubType_2 : Symbol(ISubType_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 25, 1)) | ||
>ITopType_2 : Symbol(ITopType_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 21, 2)) | ||
|
||
sKey_2?: string; | ||
>sKey_2 : Symbol(ISubType_2.sKey_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 27, 41)) | ||
} | ||
|
||
interface ITestInteface_2 { | ||
>ITestInteface_2 : Symbol(ITestInteface_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 29, 1)) | ||
|
||
[pA_2: string]: ITopType_2; | ||
>pA_2 : Symbol(pA_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 32, 3)) | ||
>ITopType_2 : Symbol(ITopType_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 21, 2)) | ||
|
||
[pB_2: `sub_${string}`]: ISubType_2; | ||
>pB_2 : Symbol(pB_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 33, 3)) | ||
>ISubType_2 : Symbol(ISubType_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 25, 1)) | ||
} | ||
|
||
const testObj2: ITestInteface_2 = { | ||
>testObj2 : Symbol(testObj2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 36, 5)) | ||
>ITestInteface_2 : Symbol(ITestInteface_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 29, 1)) | ||
|
||
a: { tKey_2: "tVal_2 " }, | ||
>a : Symbol(a, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 36, 35)) | ||
>tKey_2 : Symbol(tKey_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 37, 6)) | ||
|
||
sub_b: { tKey_2: "tVal_2 ", sKey_2: "sVal_2" }, | ||
>sub_b : Symbol(sub_b, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 37, 27)) | ||
>tKey_2 : Symbol(tKey_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 38, 10)) | ||
>sKey_2 : Symbol(sKey_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 38, 29)) | ||
|
||
}; | ||
|
||
const testObj2_2: ITestInteface_2 = { | ||
>testObj2_2 : Symbol(testObj2_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 41, 5)) | ||
>ITestInteface_2 : Symbol(ITestInteface_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 29, 1)) | ||
|
||
a: { tKey_2: "tVal_2 " }, | ||
>a : Symbol(a, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 41, 37)) | ||
>tKey_2 : Symbol(tKey_2, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 42, 6)) | ||
|
||
sub_b: { notCommon: "val3" }, | ||
>sub_b : Symbol(sub_b, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 42, 27)) | ||
>notCommon : Symbol(notCommon, Decl(commonPropertyCheckWithMultipleIndexSignatures1.ts, 43, 10)) | ||
|
||
}; | ||
|
Oops, something went wrong.
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.
This is where the
allowExtraPropertyChecks
is toggled~ when relating to atargetInfo.type
. The source is related to all target infos (that's what theindexSignaturesRelatedTo
caller does). Those checks should only be performed when relating to the applicable index info to reflect what happens in assignments like:In the example above,
{ someProp: string }
is only related to the applicable index info "selected" byobj.indexSignatureProp