9

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);
}

1 Answer 1

12

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 ;)

Sign up to request clarification or add additional context in comments.

1 Comment

I dont' undestand how it works), can someone explain how interpreter understands 'export import'?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.