Languages
[Edit]
EN

TypeScript - interface naming convention

13 points
Created by:
AnnLen
1795

In TypeScript interface naming convention contains 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
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.