@@ -365,7 +365,7 @@ export default iterateJsdoc(({
365365
366366 /**
367367 * An array-literal annotation whose element type is a literal (or union of
368- * literals) — `/** @ type {ViewType[] } *\/ ` on `['single-panel', 'user']` —
368+ * literals) — `type {ViewType[]}` on `['single-panel', 'user']` —
369369 * narrows the element type that the bare literal would widen (`string[]` ->
370370 * `ViewType[]`). Like the tuple idiom, the literal takes that element type
371371 * only *from* the annotation, so the contextually-typed initializer echoes
@@ -385,6 +385,29 @@ export default iterateJsdoc(({
385385 return isLiteralType ( elementType ) ;
386386 } ;
387387
388+ /**
389+ * Whether `operand` is an object literal carrying a method or function-valued
390+ * property. Under a surrounding `@type` object annotation such a function is
391+ * contextually typed by the annotation — its otherwise-implicit-`any`
392+ * parameters (and hence its signature) come straight from it — so
393+ * `getTypeAtLocation` echoes the asserted object shape back and a genuine
394+ * typing looks redundant. As elsewhere in this rule the uncontaminated type
395+ * cannot be recovered here, so such literals are left alone (at the cost of
396+ * missing the rare object annotation that only restates a fully
397+ * self-evident method signature).
398+ * @param {import('@typescript-eslint/utils').TSESTree.Node | null | undefined } operand
399+ * @returns {boolean }
400+ */
401+ const hasContextuallyTypedFunctionMember = ( operand ) => {
402+ return operand ?. type === 'ObjectExpression' &&
403+ operand . properties . some ( ( property ) => {
404+ return property . type === 'Property' && (
405+ property . value . type === 'FunctionExpression' ||
406+ property . value . type === 'ArrowFunctionExpression'
407+ ) ;
408+ } ) ;
409+ } ;
410+
388411 /**
389412 * Whether every element of `tupleType` is a literal type, so a `const`
390413 * assertion would reproduce the same element types (`['foo', 1]` but not
@@ -467,7 +490,10 @@ export default iterateJsdoc(({
467490 return ;
468491 }
469492
470- if ( narrowsArrayLiteralElement ( declAssertedType , decl . init ) ) {
493+ if (
494+ narrowsArrayLiteralElement ( declAssertedType , decl . init ) ||
495+ hasContextuallyTypedFunctionMember ( decl . init )
496+ ) {
471497 return ;
472498 }
473499
@@ -548,7 +574,10 @@ export default iterateJsdoc(({
548574 return ;
549575 }
550576
551- if ( narrowsArrayLiteralElement ( castAssertedType , node ) ) {
577+ if (
578+ narrowsArrayLiteralElement ( castAssertedType , node ) ||
579+ hasContextuallyTypedFunctionMember ( node )
580+ ) {
552581 return ;
553582 }
554583
0 commit comments