Skip to content

nested class declaration #14413

@farfromrefug

Description

@farfromrefug

I am trying to write a declaration file for the Titanium Mobile framework.
To do so i need to declare nested classes. Let me explain
In the Titanium mobile javascript environnement you have a global var Titanium
it would look like something like this:

declare module titanium {
    class Proxy extends EventEmitter {}
    class Module extends EventEmitter {}
    class View extends Proxy {}
    class TitaniumModule extends Module {
        UI: UIModule
    }
    class UIModule extends Module {
        View = View
    }
    export var Titanium: TitaniumModule
}

The idea is that you can do:

Titanium.UI.on('event', function() {}) ///eventEmitter

as well as

var view = new Titanium.UI.View();

The example i wrote for the declaration file does not work because of the error Initializers are not allowed in ambient contexts for all nested class declarations.
I also can't make Titanium.UI a namespace because then i cant have it extend Module and thus EventEmitter

Is there a way achieve this right now?
I saw that trick but it does not seem to work anymore.

It seems that it could be achieved if i was actually writing the objects and not just the declaration file, using static nested classes (thus the title). Could be added as a feature in a .d.ts file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions