mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Fix codefix for noPropertyAccessFromIndexSignature
This commit is contained in:
@@ -25896,7 +25896,7 @@ namespace ts {
|
||||
|
||||
propType = (compilerOptions.noUncheckedIndexedAccess && !isAssignmentTarget(node)) ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type;
|
||||
if (compilerOptions.noPropertyAccessFromIndexSignature && isPropertyAccessExpression(node)) {
|
||||
error(node, Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, unescapeLeadingUnderscores(right.escapedText));
|
||||
error(right, Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, unescapeLeadingUnderscores(right.escapedText));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -662,8 +662,6 @@ namespace ts {
|
||||
{
|
||||
name: "noPropertyAccessFromIndexSignature",
|
||||
type: "boolean",
|
||||
affectsBindDiagnostics: true,
|
||||
affectsSemanticDiagnostics: true,
|
||||
showInSimplifiedHelpView: false,
|
||||
category: Diagnostics.Additional_Checks,
|
||||
description: Diagnostics.Require_undeclared_properties_from_index_signatures_to_use_element_accesses
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(24,1): error TS4111: Property 'foo' comes from an index signature, so it must be accessed with ['foo'].
|
||||
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(32,1): error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
||||
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(40,1): error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
||||
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(24,3): error TS4111: Property 'foo' comes from an index signature, so it must be accessed with ['foo'].
|
||||
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(32,3): error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
||||
tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(40,4): error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
||||
|
||||
|
||||
==== tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts (3 errors) ====
|
||||
@@ -28,7 +28,7 @@ tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(
|
||||
|
||||
// access index signature
|
||||
b.foo;
|
||||
~~~~~
|
||||
~~~
|
||||
!!! error TS4111: Property 'foo' comes from an index signature, so it must be accessed with ['foo'].
|
||||
b["foo"];
|
||||
|
||||
@@ -38,7 +38,7 @@ tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(
|
||||
|
||||
// access index signature
|
||||
c.bar;
|
||||
~~~~~
|
||||
~~~
|
||||
!!! error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
||||
c["bar"];
|
||||
|
||||
@@ -48,7 +48,7 @@ tests/cases/conformance/additionalChecks/noPropertyAccessFromIndexSignature1.ts(
|
||||
|
||||
// optional access index signature
|
||||
d?.bar;
|
||||
~~~~~~
|
||||
~~~
|
||||
!!! error TS4111: Property 'bar' comes from an index signature, so it must be accessed with ['bar'].
|
||||
d?.["bar"];
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// @noPropertyAccessFromIndexSignature: true
|
||||
//// declare let x: { y: { [x: string]: string } };
|
||||
//// x.y.yadda;
|
||||
|
||||
verify.codeFix({
|
||||
description: [ts.Diagnostics.Use_element_access_for_0.message, 'yadda'],
|
||||
index: 0,
|
||||
newFileContent:
|
||||
`declare let x: { y: { [x: string]: string } };
|
||||
x.y["yadda"];`,
|
||||
});
|
||||
Reference in New Issue
Block a user