Typescript,类内部接口?

Hig*_*igh 4 nested interface class typescript

我找不到有关此的任何文章。

我如何定义一个嵌套interfaceclass

export class Car {

  export interface Config {
    name : string
  }

  constructor ( config : Config ) {  }

}
Run Code Online (Sandbox Code Playgroud)

Tit*_*mir 7

您不能直接这样做。但是,至少可以从外部使用者的角度出发,可以使用名称空间类合并来达到所需的效果:

export class Car {


    constructor(config: Car.Config) { }
}
namespace Car {
    export interface Config {
        name: string
    }

}

let c: Car.Config;
Run Code Online (Sandbox Code Playgroud)

  • 非常感谢你。 (2认同)