Reference to inner classes in typescript

I can successfully declare a nested class as follows:

class Outer { static Inner = class Inner { }; } 

However, I would like my outer class to contain some instances of my inner class:

 class Outer { constructor() { this.inners = [new Outer.Inner()]; } static Inner = class Inner { }; inners: Array<Inner>; // this line errors } 

But that gives me error TS2304: Cannot find name 'Inner' .

How can I do this job?

+5
source share
1 answer

Not sure if this can be achieved this way, however, as a workaround:

 class Outer { inners: Array<Outer.Inner>; } namespace Outer { export class Inner { } } 

Note: class must be defined before namespace.

See in action

+1
source

Source: https://habr.com/ru/post/1257584/


All Articles