Jon Lamb
Jon Lamb

Reputation: 1473

Typescript - Import Namespace Into Another Namespace

I'm wondering if it's possible to export a namespace from one typescript .d.ts file and then import that namespace into another .d.ts file where it gets used inside of a namespace.

Example:

namespace_export.d.ts

export namespace Foo {
    interface foo {
        prop1: string;
    }
}

types.d.ts

import { Foo } from './namespace_export'

export namespace Types {
    Foo // <-- This doesn't work but is what I would like
    interface Bar {
        prop2: string
    }
}

testfile.ts

import { Types } from './types'

function testTypes(type: Types.Foo.foo) {
    console.log(type);
}

Upvotes: 9

Views: 5307

Answers (1)

Jorgeblom
Jorgeblom

Reputation: 3578

I was wondering how to achieve this too. I found this solution:

import { Foo as fooAlias } from './namespace_export'
export namespace Types {
  export import Foo = fooAlias;
  interface Bar {
    prop2: string
  }
}

Hope this helps ;)

Upvotes: 12

Related Questions