I
(interface-name-prefix
)Interfaces often represent important software contracts, so it can be helpful to prefix their names with I
. The unprefixed name is then available for a class that provides a standard implementation of the interface. Alternatively, the contributor guidelines for the TypeScript repo suggest never prefixing interfaces with I
.
This rule enforces whether or not the I
prefix is required for interface names. The _
prefix is sometimes used to designate a private declaration, so the rule also supports a private interface that might be named _IAnimal
instead of IAnimal
.
This rule has an object option:
{ "prefixWithI": "never" }
: (default) disallows all interfaces being prefixed with "I"
or "_I"
{ "prefixWithI": "always" }
: requires all interfaces be prefixed with "I"
(but does not allow "_I"
){ "prefixWithI": "always", "allowUnderscorePrefix": true }
: requires all interfaces be prefixed with either "I"
or "_I"
For backwards compatibility, this rule supports a string option instead:
"never"
: Equivalent to { "prefixWithI": "never" }
"always"
: Equivalent to { "prefixWithI": "always" }
Configuration: { "prefixWithI": "never" }
The following patterns are considered warnings:
interface IAnimal { name: string; } interface IIguana { name: string; } interface _IAnimal { name: string; }
The following patterns are not warnings:
interface Animal { name: string; } interface Iguana { name: string; }
Configuration: { "prefixWithI": "always" }
The following patterns are considered warnings:
interface Animal { name: string; } interface Iguana { name: string; } interface _IAnimal { name: string; }
The following patterns are not warnings:
interface IAnimal { name: string; } interface IIguana { name: string; }
Configuration: { "prefixWithI": "always", "allowUnderscorePrefix": true }
The following patterns are considered warnings:
interface Animal { name: string; } interface Iguana { name: string; }
The following patterns are not warnings:
interface IAnimal { name: string; } interface IIguana { name: string; } interface _IAnimal { name: string; }
If you do not want to enforce interface name prefixing.
TypeScript Interfaces
TSLint: interface-name