Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript, interface inside class?

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 ) {  }

}
like image 810
High Avatar asked Jan 06 '19 19:01

High


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;
like image 120
Titian Cernicova-Dragomir Avatar answered Sep 30 '22 19:09

Titian Cernicova-Dragomir