@@ -64,6 +64,7 @@ export type VitestFnType =
64
64
| 'unknown'
65
65
| 'hook'
66
66
| 'vi'
67
+ | 'expectTypeOf'
67
68
68
69
interface ResolvedVitestFn {
69
70
original : string | null ,
@@ -95,7 +96,7 @@ interface ModifiersAndMatcher {
95
96
args : TSESTree . CallExpression [ 'arguments' ] ;
96
97
}
97
98
98
- interface BaseParsedJestFnCall {
99
+ interface BaseParsedVitestFnCall {
99
100
/**
100
101
* The name of the underlying Vitest function that is being called.
101
102
* This is the result of `(head.original ?? head.local)`.
@@ -106,12 +107,12 @@ interface BaseParsedJestFnCall {
106
107
members : KnownMemberExpressionProperty [ ] ;
107
108
}
108
109
109
- interface ParsedGeneralVitestFnCall extends BaseParsedJestFnCall {
110
- type : Exclude < VitestFnType , 'expect' >
110
+ interface ParsedGeneralVitestFnCall extends BaseParsedVitestFnCall {
111
+ type : Exclude < VitestFnType , 'expect' > & Exclude < VitestFnType , 'expectTypeOf' >
111
112
}
112
113
113
- export interface ParsedExpectVitestFnCall extends BaseParsedJestFnCall , ModifiersAndMatcher {
114
- type : 'expect'
114
+ export interface ParsedExpectVitestFnCall extends BaseParsedVitestFnCall , ModifiersAndMatcher {
115
+ type : 'expect' | 'expectTypeOf'
115
116
}
116
117
117
118
export type ParsedVitestFnCall = ParsedGeneralVitestFnCall | ParsedExpectVitestFnCall
@@ -128,7 +129,7 @@ export const isTypeOfVitestFnCall = (
128
129
export const parseVitestFnCall = (
129
130
node : TSESTree . CallExpression ,
130
131
context : TSESLint . RuleContext < string , unknown [ ] >
131
- ) => {
132
+ ) : ParsedVitestFnCall | null => {
132
133
const vitestFnCall = parseVitestFnCallWithReason ( node , context )
133
134
134
135
if ( typeof vitestFnCall === 'string' )
@@ -145,7 +146,7 @@ const parseVitestFnCallCache = new WeakMap<
145
146
export const parseVitestFnCallWithReason = (
146
147
node : TSESTree . CallExpression ,
147
148
context : TSESLint . RuleContext < string , unknown [ ] >
148
- ) => {
149
+ ) : ParsedVitestFnCall | string | null => {
149
150
let parsedVistestFnCall = parseVitestFnCallCache . get ( node )
150
151
151
152
if ( parsedVistestFnCall )
@@ -162,6 +163,9 @@ const determineVitestFnType = (name: string): VitestFnType => {
162
163
if ( name === 'expect' )
163
164
return 'expect'
164
165
166
+ if ( name === 'expectTypeOf' )
167
+ return 'expectTypeOf'
168
+
165
169
if ( name === 'vi' )
166
170
return 'vi'
167
171
@@ -231,15 +235,15 @@ const findModifiersAndMatcher = (
231
235
return 'matcher-not-found'
232
236
}
233
237
234
- const parseVitestExpectCall = ( typelessParsedVitestFnCall : Omit < ParsedVitestFnCall , 'type' > ) : ParsedExpectVitestFnCall | string => {
238
+ const parseVitestExpectCall = ( typelessParsedVitestFnCall : Omit < ParsedVitestFnCall , 'type' > , type : 'expect' | 'expectTypeOf' ) : ParsedExpectVitestFnCall | string => {
235
239
const modifiersMatcher = findModifiersAndMatcher ( typelessParsedVitestFnCall . members )
236
240
237
241
if ( typeof modifiersMatcher === 'string' )
238
242
return modifiersMatcher
239
243
240
244
return {
241
245
...typelessParsedVitestFnCall ,
242
- type : 'expect' ,
246
+ type,
243
247
...modifiersMatcher
244
248
}
245
249
}
@@ -300,7 +304,7 @@ const parseVistestFnCallWithReasonInner = (
300
304
301
305
const links = [ name , ...rest . map ( getAccessorValue ) ]
302
306
303
- if ( name !== 'vi' && name !== 'expect' && ! ValidVitestFnCallChains . includes ( links . join ( '.' ) ) )
307
+ if ( name !== 'vi' && name !== 'expect' && name !== 'expectTypeOf' && ! ValidVitestFnCallChains . includes ( links . join ( '.' ) ) )
304
308
return null
305
309
306
310
const parsedVitestFnCall : Omit < ParsedVitestFnCall , 'type' > = {
@@ -311,8 +315,8 @@ const parseVistestFnCallWithReasonInner = (
311
315
312
316
const type = determineVitestFnType ( name )
313
317
314
- if ( type === 'expect' ) {
315
- const result = parseVitestExpectCall ( parsedVitestFnCall )
318
+ if ( type === 'expect' || type === 'expectTypeOf' ) {
319
+ const result = parseVitestExpectCall ( parsedVitestFnCall , type )
316
320
317
321
if ( typeof result === 'string' && findTopMostCallExpression ( node ) !== node )
318
322
return null
0 commit comments