File tree Expand file tree Collapse file tree 6 files changed +14
-12
lines changed Expand file tree Collapse file tree 6 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 53
53
"natural-compare-lite" : " ^1.4.0" ,
54
54
"regexpp" : " ^3.2.0" ,
55
55
"semver" : " ^7.3.7" ,
56
- "ts-api-utils" : " ^0.0.21 "
56
+ "ts-api-utils" : " ^0.0.22 "
57
57
},
58
58
"devDependencies" : {
59
59
"@types/debug" : " *" ,
Original file line number Diff line number Diff line change 1
1
import type { TSESTree } from '@typescript-eslint/utils' ;
2
2
import { AST_NODE_TYPES } from '@typescript-eslint/utils' ;
3
3
import * as tools from 'ts-api-utils' ;
4
+ import * as ts from 'typescript' ;
4
5
5
6
import * as util from '../util' ;
6
7
import { getThisExpression } from '../util' ;
@@ -82,9 +83,11 @@ export default util.createRule({
82
83
// so we have to use the contextual typing in these cases, i.e.
83
84
// const foo1: () => Set<string> = () => new Set<any>();
84
85
// the return type of the arrow function is Set<any> even though the variable is typed as Set<string>
85
- let functionType = tools . isExpression ( functionTSNode )
86
- ? util . getContextualType ( checker , functionTSNode )
87
- : services . getTypeAtLocation ( functionNode ) ;
86
+ let functionType =
87
+ ts . isFunctionExpression ( functionTSNode ) ||
88
+ ts . isArrowFunction ( functionTSNode )
89
+ ? util . getContextualType ( checker , functionTSNode )
90
+ : services . getTypeAtLocation ( functionNode ) ;
88
91
if ( ! functionType ) {
89
92
functionType = services . getTypeAtLocation ( functionNode ) ;
90
93
}
Original file line number Diff line number Diff line change 42
42
"@typescript-eslint/typescript-estree" : " 5.52.0" ,
43
43
"@typescript-eslint/utils" : " 5.52.0" ,
44
44
"debug" : " ^4.3.4" ,
45
- "ts-api-utils" : " ^0.0.21 "
45
+ "ts-api-utils" : " ^0.0.22 "
46
46
},
47
47
"devDependencies" : {
48
48
"@typescript-eslint/parser" : " 5.52.0" ,
Original file line number Diff line number Diff line change 1
- import * as tools from 'ts-api-utils' ;
2
1
import * as ts from 'typescript' ;
3
2
4
3
/**
@@ -23,7 +22,7 @@ export function getContextualType(
23
22
} else if (
24
23
ts . isVariableDeclaration ( parent ) ||
25
24
ts . isPropertyDeclaration ( parent ) ||
26
- tools . isParameterDeclaration ( parent )
25
+ ts . isParameter ( parent )
27
26
) {
28
27
return parent . type ? checker . getTypeFromTypeNode ( parent . type ) : undefined ;
29
28
} else if ( ts . isJsxExpression ( parent ) ) {
Original file line number Diff line number Diff line change 48
48
"globby" : " ^11.1.0" ,
49
49
"is-glob" : " ^4.0.3" ,
50
50
"semver" : " ^7.3.7" ,
51
- "ts-api-utils" : " ^0.0.21 "
51
+ "ts-api-utils" : " ^0.0.22 "
52
52
},
53
53
"devDependencies" : {
54
54
"@babel/code-frame" : " *" ,
Original file line number Diff line number Diff line change @@ -13714,10 +13714,10 @@ trough@^1.0.0:
13714
13714
resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.5.tgz#b8b639cefad7d0bb2abd37d433ff8293efa5f406"
13715
13715
integrity sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA==
13716
13716
13717
- ts-api-utils@^0.0.21 :
13718
- version "0.0.21 "
13719
- resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-0.0.21 .tgz#d5e58e3200f848123a89f3987d6ee9b613642d01 "
13720
- integrity sha512-Dr9RHp5+4jLF+2wARhwQO1Z/6BFVsKigZhascnbsbyzSEDKO9qGlN7RgsquqHwP0lHiQmLJFYiGCLXTmcDC9Wg ==
13717
+ ts-api-utils@^0.0.22 :
13718
+ version "0.0.22 "
13719
+ resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-0.0.22 .tgz#c58aac346f3990e6e164b4907aca57f54d81a2e8 "
13720
+ integrity sha512-XrQNMP/CQk2gOa+NfNIxNSf60n+RsC7tAkyCxhwnkShxUFpitvwNDfDxdMIZxHtdKKqqeRi94T191sNN7pFSrg ==
13721
13721
13722
13722
ts-essentials@^2.0.3:
13723
13723
version "2.0.12"
You can’t perform that action at this time.
0 commit comments