Languages
[Edit]
EN

TypeScript - interface naming convention

13 points
Created by:
AnnLen
10120

In TypeScript interface naming convention defines following rules:

  1. Use PascalCase for interface names.
  2. Use pascalCase for interface members.
  3. Do not use "I" as a prefix for interface names.
  4. Use whole words in names when possible.

Interface naming convention example

interface Square {
    readonly name: string;

    computePerimeter(aSize : number, bSize : number) : number;
    computeArea(aSize: number, bSize: number): number;

    toString(): string;
}

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.

References

  1. TypeScript Handbook Interface - Microsoft Github Docs
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - friendly IT community for everyone.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join