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.
This rule enforces whether or not the I
prefix is required for interface names.
This rule has a string option.
"never"
(default) disallows all interfaces being prefixed with"I"
(or"_I"
)"always"
requires all interfaces be prefixed with"I"
(or"_I"
)
The _
prefix is sometimes used to designate a private declaration, in which case a private interface might be
named _IAnimal
instead of IAnimal
. The rule recognizes both forms.
TypeScript suggests never prefixing interfaces with "I".
The following patterns are considered warnings:
interface IAnimal {
name: string;
}
interface _IAnimal {
name: string;
}
interface IIguana {
name: string;
}
The following patterns are not warnings:
interface Animal {
name: string;
}
interface Iguana {
name: string;
}
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 _IAnimal {
name: string;
}
interface IIguana {
name: string;
}
If you do not want to enforce interface name prefixing.
TypeScript Interfaces
TSLint: interface-name