@@ -336,6 +336,44 @@ const getCallee = (node) => {
336336 * @return {import('typescript').Declaration | null }
337337 */
338338const getCalleeDeclaration = ( services , node ) => {
339+ /**
340+ * Return type of setter when assigning
341+ *
342+ * @example
343+ * ```
344+ * foo.bar = 'baz';
345+ * // ^ This can be a setter
346+ * ```
347+ */
348+ if ( node . type === AST_NODE_TYPES . AssignmentExpression ) {
349+ /** @type {import('@typescript-eslint/utils').TSESTree.Node | null } */
350+ const calleeNode = getCallee ( node ) ;
351+ if ( ! calleeNode ) return null ;
352+
353+ const type = services . getTypeAtLocation ( calleeNode ) ;
354+ for (
355+ const declaration of
356+ type . symbol ?. declarations ??
357+ services
358+ . getSymbolAtLocation ( calleeNode )
359+ ?. declarations ??
360+ [ ]
361+ ) {
362+ if ( ! services . tsNodeToESTreeNodeMap . has ( declaration ) ) continue ;
363+
364+ const declarationNode =
365+ services . tsNodeToESTreeNodeMap . get ( declaration ) ;
366+
367+ const isSetter = isAccessorNode ( declarationNode ) &&
368+ declarationNode . kind === 'set' ;
369+
370+ if ( isSetter ) {
371+ return declaration ;
372+ }
373+ }
374+ return null ;
375+ }
376+
339377 /** @type {import('typescript').Declaration | null } */
340378 let declaration = null ;
341379 if (
@@ -371,24 +409,6 @@ const getCalleeDeclaration = (services, node) => {
371409 if ( ! declaration ) return null ;
372410
373411 switch ( node . type ) {
374- /**
375- * Return type of setter when assigning
376- *
377- * @example
378- * ```
379- * foo.bar = 'baz';
380- * // ^ This can be a setter
381- * ```
382- */
383- case AST_NODE_TYPES . AssignmentExpression : {
384- const declarationNode =
385- services . tsNodeToESTreeNodeMap . get ( declaration ) ;
386-
387- const isSetter = isAccessorNode ( declarationNode ) &&
388- declarationNode . kind === 'set' ;
389-
390- return isSetter ? declaration : null ;
391- }
392412 /**
393413 * Return type of getter when accessing
394414 *
0 commit comments