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);
}
                TypeScript - Namespaces. A namespace is a way to logically group related code. This is inbuilt into TypeScript unlike in JavaScript where variables declarations go into a global scope and if multiple JavaScript files are used within same project there will be possibility of overwriting or misconstruing the same variables,...
The import Users = part is called an “alias” in Typescript and it’s another piece of interesting code. Again took me a loooot of time to bump into it. It’s a variable at runtime but it also has typing information inside. And it can be used as a “wrapper”, the same way namespaces and modules are used.
Using Namespaces #. Namespaces are simply named JavaScript objects in the global namespace. This makes namespaces a very simple construct to use. They can span multiple files, and can be concatenated using --outFile.
Namespaces are a TypeScript-specific way to organize code. Namespaces are simply named JavaScript objects in the global namespace. This makes namespaces a very simple construct to use. Unlike modules, they can span multiple files, and can be concatenated using outFile .
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 ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With