1

The best way to describe my problem is to show the code:

I have ns.d.ts:

declare namespace ns {
}

and a lot of .ts files that're using this namespace:

let a = new ns.ClassOne();
let c = new ns.submodule.function(23);

Output:

error TS2694: Namespace 'ns' has no exported member 'ClassOne'.
error TS2708: Cannot use namespace 'ns' as a value.

Basically, I have a huuuge namespace and a codebase that uses it's classes, submodules and functions. The problem is, I don't want to write the whole types definitions - I want typescript to completely ignore it.

Is there any way to define this namespace, so TypeScript will acknowledge I know what I'm doing and will allow me to use this namespace without forcing me to type everything it contains?

Sabikku2
  • 11
  • 1
  • [How do you produce a .d.ts “typings” definition file from an existing JavaScript library?](https://stackoverflow.com/questions/12687779/how-do-you-produce-a-d-ts-typings-definition-file-from-an-existing-javascript) – user7860670 Jan 18 '19 at 17:05
  • Thanks, as I wrote in the Titian's answer, those methods didn't work for me. – Sabikku2 Jan 18 '19 at 17:14
  • "didn't work" is not a problem description – user7860670 Jan 18 '19 at 17:15
  • Neither `declare module "ns";` nor `declare const ns:any;` made the error 2503 dissapear. The exact example is a line like: `let a : ns.ClassOne = null;`. Even after declaring ns using those methods, I still get 2503 on this line. – Sabikku2 Jan 18 '19 at 17:18
  • My suggestion was to generate and use complete typings. – user7860670 Jan 18 '19 at 17:19

1 Answers1

0

Just declare the namespace as a variable of type any. The compiler will not check any access on the variable.

declare const ns:any;
let a = new ns.ClassOne();
let c = new ns.submodule.function(23);
Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357
  • Thanks, I tried exactly this method and it didn't work. The exact example here would be a line like: `let a : ns.ClassOne = null;`. It gives me 2503: cannot find namespace ns – Sabikku2 Jan 18 '19 at 17:13
  • @Sabikku2 are you also using a module system ? where is the const defined ? the above code works in the playground. – Titian Cernicova-Dragomir Jan 18 '19 at 17:21