Skip to content

Commit

Permalink
improve object access detection (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
pipopotamasu authored Feb 23, 2024
1 parent a558335 commit 0fce0df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions rules/no-implicit-any/member-expression/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,20 @@ ruleTester.run('member-expression', rule, {
`,
errors: [{ messageId: 'missingAnyType' }],
},
{
code: `
function fn (arg: { foo: string }) {
const keyName: string = 'bar';
arg[keyName];
}
`,
output: `
function fn (arg: { foo: string }) {
const keyName: string = 'bar';
(arg as any)[keyName];
}
`,
errors: [{ messageId: 'missingAnyType' }],
},
],
});
2 changes: 1 addition & 1 deletion rules/no-implicit-any/member-expression/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const lintMemberExpression = (
const nodeType = parserServices.getTypeAtLocation(node);
const objType = parserServices.getTypeAtLocation(node.object);

if (nodeType.flags === ts.TypeFlags.Any && objType.symbol?.escapedName === '__object') {
if (nodeType.flags === ts.TypeFlags.Any && objType.symbol?.escapedName !== 'Array') {
context.report({
node,
messageId: 'missingAnyType',
Expand Down

0 comments on commit 0fce0df

Please sign in to comment.