File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 6
6
import {
7
7
CallExpressionWithSingleArgument ,
8
8
KnownCallExpression ,
9
+ MaybeTypeCast ,
9
10
ModifierName ,
10
11
NotNegatableParsedModifier ,
11
12
ParsedEqualityMatcherCall ,
@@ -27,7 +28,7 @@ const isBooleanLiteral = (node: TSESTree.Node): node is BooleanLiteral =>
27
28
node . type === AST_NODE_TYPES . Literal && typeof node . value === 'boolean' ;
28
29
29
30
type ParsedBooleanEqualityMatcherCall = ParsedEqualityMatcherCall <
30
- BooleanLiteral
31
+ MaybeTypeCast < BooleanLiteral >
31
32
> ;
32
33
33
34
/**
@@ -104,7 +105,7 @@ const getNegationFixes = (
104
105
const negationPropertyDot = findPropertyDotToken ( modifier . node , sourceCode ) ;
105
106
106
107
const toContainFunc = buildToContainFuncExpectation (
107
- matcher . arguments [ 0 ] . value ,
108
+ followTypeAssertionChain ( matcher . arguments [ 0 ] ) . value ,
108
109
) ;
109
110
110
111
/* istanbul ignore if */
@@ -218,7 +219,7 @@ export default createRule({
218
219
}
219
220
220
221
const toContainFunc = buildToContainFuncExpectation (
221
- ! matcher . arguments [ 0 ] . value ,
222
+ ! followTypeAssertionChain ( matcher . arguments [ 0 ] ) . value ,
222
223
) ;
223
224
224
225
const [ containArg ] = includesCall . arguments ;
Original file line number Diff line number Diff line change @@ -33,14 +33,21 @@ interface TypeAssertionChain<
33
33
Expression extends TSESTree . Expression = TSESTree . Expression
34
34
> extends TSESTree . TSTypeAssertion {
35
35
// expression: TypeAssertionChain<Expression> | Expression;
36
- expression : any ; // https://github.com/ typescript-eslint/typescript-eslint/issues/802
36
+ expression : any ; // todo: replace w/ above once typescript-eslint is updated to v2.0.0
37
37
}
38
38
39
- export const followTypeAssertionChain = (
40
- expression : TSESTree . Expression | TSTypeCastExpression ,
41
- ) : TSESTree . Expression =>
42
- expression . type === AST_NODE_TYPES . TSAsExpression ||
43
- expression . type === AST_NODE_TYPES . TSTypeAssertion
39
+ const isTypeCastExpression = < Expression extends TSESTree . Expression > (
40
+ node : MaybeTypeCast < Expression > ,
41
+ ) : node is TSTypeCastExpression < Expression > =>
42
+ node . type === AST_NODE_TYPES . TSAsExpression ||
43
+ node . type === AST_NODE_TYPES . TSTypeAssertion ;
44
+
45
+ export const followTypeAssertionChain = <
46
+ Expression extends TSESTree . Expression
47
+ > (
48
+ expression : MaybeTypeCast < Expression > ,
49
+ ) : Expression =>
50
+ isTypeCastExpression ( expression )
44
51
? followTypeAssertionChain ( expression . expression )
45
52
: expression ;
46
53
You can’t perform that action at this time.
0 commit comments