EN
TypeScript - interface naming convention
31
points
This article explains the rules for interface naming convention used in TypeScript.
The interface naming convention defines the following rules:
- Use PascalCase for interface names.
- Use camelCase for interface members.
- Do not use "I" as a prefix for interface names.
- Use whole words in names when possible.
Example predefined interfaces: Window
, Document
, etc.
Interface naming convention example
interface Square {
readonly name: string;
computePerimeter(aSize: number, bSize: number): number;
computeArea(aSize: number, bSize: number): number;
toString(): string;
}
Interface implementation:
class LocalSquare implements Square {
get name(): string {
return 'Square';
}
public computePerimeter(aSize: number, bSize: number): number {
return 2 * aSize + 2 * bSize;
}
public computeArea(aSize: number, bSize: number): number {
return aSize * bSize;
}
public toString(): string {
return `[ ${this.name} object ]`;
}
}
Run it online here.