typescript ,类内的接口(interface)?

标签 typescript class interface nested

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

如何在 class 中定义嵌套的 interface

export class Car {

  export interface Config {
    name : string
  }

  constructor ( config : Config ) {  }

}

最佳答案

你不能直接这样做。但是至少从外部消费者的角度来看,您可以使用 namespace 类合并来达到预期的效果:

export class Car {


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

}

let c: Car.Config;

关于 typescript ,类内的接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54065250/

相关文章:

javascript - 如何更改数组以组合属于同一属性的值

Python:为什么 Tkinter 类实例化必须使用框架?

c++ - 为什么我不能在我的类中声明这个对象?

PHP - 让您的类完成所有工作而不对使用该类的脚本做太多工作是否可以?

java - Java 接口(interface)定义中的语句在什么上下文中执行?

java - PECS 不适用于具有接口(interface)的返回类型

typescript - 如何强制回调参数的类型合规性

typescript - 从 elasticsearch 聚合返回复杂的嵌套文档

打开的 Angular 对话框不起作用

C# 最佳实践 : Using a delegate or an interface as a class dependency