diff --git a/src/rules/noUnboundMethodRule.ts b/src/rules/noUnboundMethodRule.ts index e798c6a7589..bed52753504 100644 --- a/src/rules/noUnboundMethodRule.ts +++ b/src/rules/noUnboundMethodRule.ts @@ -124,8 +124,9 @@ function isSafeUse(node: ts.Node): boolean { return (parent as ts.CallExpression).expression === node; case ts.SyntaxKind.TaggedTemplateExpression: return (parent as ts.TaggedTemplateExpression).tag === node; - // E.g. `obj.method.bind(obj)`. + // E.g. `obj.method.bind(obj) or obj.method["prop"]`. case ts.SyntaxKind.PropertyAccessExpression: + case ts.SyntaxKind.ElementAccessExpression: return true; // Allow most binary operators, but don't allow e.g. `myArray.forEach(obj.method || otherObj.otherMethod)`. case ts.SyntaxKind.BinaryExpression: diff --git a/test/rules/no-unbound-method/default/test.ts.lint b/test/rules/no-unbound-method/default/test.ts.lint index adc08b15ca8..53d3ba61f8f 100644 --- a/test/rules/no-unbound-method/default/test.ts.lint +++ b/test/rules/no-unbound-method/default/test.ts.lint @@ -6,6 +6,7 @@ function f(i: I) { i.m ? 1 : 2; if (i.m) {} !i.m; + i.m["length"]; return i.m!; ~~~ [0] }