@vitest/eslint-plugin rule vitest/prefer-expect-type-of suggests/autofixes:
expect(typeof value).toBe("function")
to
expectTypeOf(value).toBeFunction()
But in my setup this can fail TypeScript checking with:
TS2349: This expression is not callable.
Type 'ExpectFunction<unknown>' has no call signatures.
Environment
@vitest/eslint-plugin: 1.6.11
vitest: 4.1.0
- TypeScript:
5.9.3
- Node:
25.8.1
- OS: Windows 11
repro from repository code
if (firstSuggestion !== undefined) {
expect(typeof firstSuggestion.fix).toBe("function");
}
When vitest/prefer-expect-type-of is enabled and autofix is applied, this becomes:
expectTypeOf(firstSuggestion.fix).toBeFunction();
Then TypeScript can fail with:
TS2349: This expression is not callable.
Type 'ExpectFunction<unknown>' has no call signatures.
Expected behavior
Autofix should only apply when the resulting assertion is type-safe, or skip autofix if it may break typechecking.
Actual behavior
Autofix/suggestion can lead to TS compile errors for valid runtime assertions.
Would you consider guarding the fixer for cases where expectTypeOf(...).toBeFunction() is not type-safe in the current typing context somehow?
@vitest/eslint-pluginrulevitest/prefer-expect-type-ofsuggests/autofixes:to
But in my setup this can fail TypeScript checking with:
Environment
@vitest/eslint-plugin:1.6.11vitest:4.1.05.9.325.8.1repro from repository code
When
vitest/prefer-expect-type-ofis enabled and autofix is applied, this becomes:Then TypeScript can fail with:
Expected behavior
Autofix should only apply when the resulting assertion is type-safe, or skip autofix if it may break typechecking.
Actual behavior
Autofix/suggestion can lead to TS compile errors for valid runtime assertions.
Would you consider guarding the fixer for cases where
expectTypeOf(...).toBeFunction()is not type-safe in the current typing context somehow?