Skip to content

Commit 6eb7900

Browse files
committed
Show error only if noImplicitAny is set
1 parent 8ea849b commit 6eb7900

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12702,7 +12702,7 @@ namespace ts {
1270212702
}
1270312703
if (accessExpression && !isConstEnumObjectType(objectType)) {
1270412704
if (isObjectLiteralType(objectType)) {
12705-
if (indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
12705+
if (noImplicitAny && indexType.flags & (TypeFlags.StringLiteral | TypeFlags.NumberLiteral)) {
1270612706
diagnostics.add(createDiagnosticForNode(accessExpression, Diagnostics.Property_0_does_not_exist_on_type_1, (indexType as StringLiteralType).value, typeToString(objectType)));
1270712707
return undefinedType;
1270812708
}

tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.errors.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/baselines/reference/augmentedTypeBracketAccessIndexSignature.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ interface Function {
1616
}
1717

1818
var a = {}[0]; // Should be Foo
19-
>a : undefined
20-
>{}[0] : undefined
19+
>a : error
20+
>{}[0] : error
2121
>{} : {}
2222
>0 : 0
2323

2424
var b = (() => { })[0]; // Should be Bar
25-
>b : any
26-
>(() => { })[0] : any
25+
>b : error
26+
>(() => { })[0] : error
2727
>(() => { }) : () => void
2828
>() => { } : () => void
2929
>0 : 0

0 commit comments

Comments
 (0)