Hwang
Hwang

Reputation: 502

how to extends a module in typescript

I'm still new to typescript, so any direction would be appreciated. Thanks!

file A:

   module SoundManager {
    export class SoundManager {

    }

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

    } }

file B:

module SoundM {
    class SoundM extends SoundManager {
    }

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

this will return the error:

Error TS2507 Type 'typeof SoundManager' is not a constructor function type.

Upvotes: 1

Views: 2638

Answers (1)

basarat
basarat

Reputation: 276199

The error you speak of is demonstrated below:

enter image description here

It is actually because you are using the SoundManager namespace and not class. Fix:

module SoundManager {
    export class SoundManager {

    }

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

    }
}

module SoundM {
    class SoundM extends SoundManager.SoundManager {
    }
}

That said. Please look at using modules : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html

Upvotes: 2

Related Questions