Typescript, interface inside class?

Viewed 10649

I could not find any article about this.

How can i define a nested interface inside a class?

export class Car {

  export interface Config {
    name : string
  }

  constructor ( config : Config ) {  }

}
1 Answers

You can't do it directly. But you can use namespace-class merging to achieve the desired effect at least from the point of you of an external consumer:

export class Car {


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

}

let c: Car.Config;
Related