shytikov shytikov - 4 months ago 19
TypeScript Question

Create typings for nested namespaces in typescript

I'm trying to create typings definitions for already existed library, and having issues describe its structure properly. The problem is nested namespaces. In JavaScript full name of my method looks like this:

NameSpace1.NameSpace2.NameSpace3.MethodName()


But I'm not able to create proper
d.ts
definition file... I've tried different combinations, with
export interface
,
export module
for nested namespaces... But nothing works. The only construction that does not fire any errors is following:

declare namespace NameSpace1 {
}


But this is not enough... Do you know how to properly describe such a nested namespaces in TypeScript definitions?

Answer
declare namespace NameSpace1.NameSpace2.NameSpace3 {
  function MethodName(): void;
}

There are literally thousands of examples of how to write definition files at https://github.com/DefinitelyTyped/DefinitelyTyped ; I'd recommend looking for something similar to what you have next time you're stuck.

Comments