11import { ESLintUtils } from '@typescript-eslint/utils'
2- import ts from 'typescript'
32import { ASTUtils } from '../../utils/ast-utils'
43import { detectTanstackQueryImports } from '../../utils/detect-react-query-imports'
54import { getDocsUrl } from '../../utils/get-docs-url'
5+ import type { ParserServicesWithTypeInformation } from '@typescript-eslint/utils'
66import type { ExtraRuleDocs } from '../../types'
77
8+ const TypeFlags = {
9+ Void : 16384 ,
10+ Undefined : 32768 ,
11+ } as const
12+
813export const name = 'no-void-query-fn'
914
1015const createRule = ESLintUtils . RuleCreator < ExtraRuleDocs > ( getDocsUrl )
@@ -69,7 +74,11 @@ export const rule = createRule({
6974 } ) ,
7075} )
7176
72- function isIllegalReturn ( checker : ts . TypeChecker , type : ts . Type ) : boolean {
77+ type Program = ParserServicesWithTypeInformation [ 'program' ]
78+ type TypeChecker = ReturnType < Program [ 'getTypeChecker' ] >
79+ type Type = ReturnType < TypeChecker [ 'getTypeAtLocation' ] >
80+
81+ function isIllegalReturn ( checker : TypeChecker , type : Type ) : boolean {
7382 const awaited = checker . getAwaitedType ( type )
7483
7584 if ( ! awaited ) return false
@@ -78,7 +87,5 @@ function isIllegalReturn(checker: ts.TypeChecker, type: ts.Type): boolean {
7887 return awaited . types . some ( ( t ) => isIllegalReturn ( checker , t ) )
7988 }
8089
81- return awaited . flags & ( ts . TypeFlags . Void | ts . TypeFlags . Undefined )
82- ? true
83- : false
90+ return awaited . flags & ( TypeFlags . Void | TypeFlags . Undefined ) ? true : false
8491}
0 commit comments