Skip to content

Commit 334b859

Browse files
Domino9697RyanCavanaugh
authored andcommitted
Add check for Records in reportNonexistentProperty function (microsoft#31701)
1 parent efa19f6 commit 334b859

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20830,7 +20830,7 @@ namespace ts {
2083020830
let relatedInfo: Diagnostic | undefined;
2083120831
if (containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) {
2083220832
for (const subtype of (containingType as UnionType).types) {
20833-
if (!getPropertyOfType(subtype, propNode.escapedText)) {
20833+
if (!getPropertyOfType(subtype, propNode.escapedText) && !getIndexInfoOfType(subtype, IndexKind.String)) {
2083420834
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype));
2083520835
break;
2083620836
}

tests/baselines/reference/unionTypeWithIndexSignature.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(11,3): error TS2339: Property 'bar' does not exist on type 'Missing'.
2-
Property 'bar' does not exist on type '{ [s: string]: string; }'.
2+
Property 'bar' does not exist on type '{ foo: boolean; }'.
33
tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(14,4): error TS2540: Cannot assign to 'foo' because it is a read-only property.
44
tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(24,1): error TS7053: Element implicitly has an 'any' type because expression of type '1' can't be used to index type 'Both'.
55
Property '1' does not exist on type 'Both'.
@@ -22,7 +22,7 @@ tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(26,1): error
2222
m.bar
2323
~~~
2424
!!! error TS2339: Property 'bar' does not exist on type 'Missing'.
25-
!!! error TS2339: Property 'bar' does not exist on type '{ [s: string]: string; }'.
25+
!!! error TS2339: Property 'bar' does not exist on type '{ foo: boolean; }'.
2626
type RO = { foo: number } | { readonly [s: string]: string }
2727
declare var ro: RO
2828
ro.foo = 'not allowed'

0 commit comments

Comments
 (0)