Typescript 类何时应该实现接口?

Typescript 类何时应该实现接口?,typescript,interface,interface-implementation,Typescript,Interface,Interface Implementation,在项目中工作,并看到开发人员在typescript中执行以下操作 export class Ledger implements ILedger { LedgerID: number; CashAmmount: number; Units: number; public static someFunction { // an ajax call for example to a controller }

在项目中工作,并看到开发人员在typescript中执行以下操作

    export class Ledger implements ILedger {
      LedgerID: number;
      CashAmmount: number;
      Units: number;

      public static someFunction {
        // an ajax call for example to a controller
      }
    }

    export interface ILedger {
       LedgerID: number;
       CashAmmount: number;
       Units: number;
     }
想知道这是否是正确的做事方式。如果在类中没有实现,那么它似乎毫无意义。然后在我们的React组件中有对接口的引用,有时是对类的引用。想开始建立一些惯例,但想在这种情况下的正确做法上得到一些帮助

如果类中没有实现,那么它似乎毫无意义

我同意。那样的话没必要。但也有一些有效的案例

依赖注入 比如:

符合外部API 有人要求
IFoo
。您想在
IFoo
的代码库中使用一个类。让一个类扩展它,这样你就知道这个类总是遵循外部的IFoo