Disallow interface declarations in test files; import production types instead.
| Property | Value |
|---|---|
| Type | suggestion |
| Fixable | No |
| Recommended | warn |
| Strict | error |
Declaring an interface inside a test file is almost always a sign that the production code is not exporting a proper type contract. When a test author creates a local interface to type mock objects or fixtures, that type drifts independently from the real production shape. If the production type changes, the test's copy won't break, silently hiding regressions.
The correct fix is to define the interface in the production module and import it in the test.
// user.ts (production)
export interface IUser {
name: string;
email: string;
}
// user.test.ts
import type { IUser } from './user';
const mockUser: IUser = { name: 'Alice', email: 'alice@example.com' };// user.test.ts
interface IUser {
name: string;
email: string;
}
const mockUser: IUser = { name: 'Alice', email: 'alice@example.com' };This rule has no options:
'zero-tolerance/no-test-interface-declaration': 'error'