【问题标题】:how to extends a module in typescript如何在打字稿中扩展模块
【发布时间】:2016-07-04 21:16:16
【问题描述】:

我还是打字稿的新手,所以任何方向都会受到赞赏。谢谢!

文件 A:

   module SoundManager {
    export class SoundManager {

    }

    export function init($s: string):void {

    } }

文件 B:

module SoundM {
    class SoundM extends SoundManager {
    }

    export function init($s:string): void {
        super.init($s);
    }
}

这将返回错误:

错误 TS2507 类型“typeof SoundManager”不是构造函数类型。

【问题讨论】:

    标签: typescript


    【解决方案1】:

    您所说的错误如下所示:

    这实际上是因为您使用的是SoundManager 命名空间,而不是class。修复:

    module SoundManager {
        export class SoundManager {
    
        }
    
        export function init($s: string): void {
    
        }
    }
    
    module SoundM {
        class SoundM extends SoundManager.SoundManager {
        }
    }
    

    就是这么说的。请查看使用模块:https://basarat.gitbooks.io/typescript/content/docs/project/modules.html

    【讨论】:

      猜你喜欢
      • 2019-06-20
      • 2018-02-11
      • 1970-01-01
      • 2016-12-12
      • 2020-05-19
      • 2021-09-25
      • 1970-01-01
      • 2021-06-18
      • 1970-01-01
      相关资源
      最近更新 更多