Typescript:在命名空间中使用 new

Typescript: Using new in namespace

我正在为私有包创建 DefinitelyTyped(我无法更改源代码),但我找不到任何方法来实现这样的类型:

  GlobalNameSpace.SuperClass = function(arg) {}
  GlobalNameSpace.superClass = new GlobalNameSpace.SuperClass(args)

我的尝试:

declare namespace GlobalNameSpace {
    class SuperClass {}

    const superClass = new GlobalNameSpace.SuperClass(args);
}

可悲的是,当我这样做时,VS Code 出现错误。

A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.

知道如何解决这个问题吗?

这个怎么样:

declare namespace GlobalNameSpace {
    export class SuperClass { }
    export const superClass: typeof SuperClass;
}

在@elderapo 的帮助下修复了 https://discord.gg/typescript

最终解决方案:

declare namespace GlobalNamespace {
    class SuperKomp {
        constructor();
        public on(key: string): void;
    }

    const komp: GlobalNamespace.SuperKomp;
}

GlobalNamespace.komp.on('click');