Typescript: namespace, splitting across files

Created on 7 Jan 2017  路  2Comments  路  Source: microsoft/TypeScript



TypeScript Version: Version 2.1.4

code
Animates.Dogs.ts

export namespace Animates {
  export namespace Dogs {
    export class SmallDog {

    }
  }
}

Animates.Dogs.SmallBreeds.ts

/// <reference path="./Animates.Dogs.ts" />

export namespace Animates {
  export namespace Dogs {
    export class Chihuahua extends Animates.Dogs.SmallDog {}
  }
}

Expected behavior:
Chihuahua is kind of SmallDog

Actual behavior:

Animates.Dogs.SmallBreeds.ts(5,53): error TS2694: Namespace '"Animates.Dogs.SmallBreeds".Animates.Dogs' has no exported member 'SmallDog'.
Question

Most helpful comment

A top level import or export declaration makes the file a module. This is a duplicate of #11879
The following is what you are after (this creates a global spread across multiple files)
Animates.Dogs.ts

namespace Animates {
  export namespace Dogs {
    export class SmallDog {

    }
  }
}

Animates.Dogs.SmallBreeds.ts

/// <reference path="./Animates.Dogs.ts" />

namespace Animates {
  export namespace Dogs {
    export class Chihuahua extends Animates.Dogs.SmallDog {}
  }
}

All 2 comments

A top level import or export declaration makes the file a module. This is a duplicate of #11879
The following is what you are after (this creates a global spread across multiple files)
Animates.Dogs.ts

namespace Animates {
  export namespace Dogs {
    export class SmallDog {

    }
  }
}

Animates.Dogs.SmallBreeds.ts

/// <reference path="./Animates.Dogs.ts" />

namespace Animates {
  export namespace Dogs {
    export class Chihuahua extends Animates.Dogs.SmallDog {}
  }
}

@aluanhaddad Is there a way to use that in an npm package?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Roam-Cooper picture Roam-Cooper  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

siddjain picture siddjain  路  3Comments

manekinekko picture manekinekko  路  3Comments

blendsdk picture blendsdk  路  3Comments