How to fix 'Cannot use namespace as a type ts(2709)' in typescript?

You need to export it inside module declaration:

declare module 'sorted-array' {
  class SortedArray {
    constructor(arr: number[]);
    search(element: any): number;
  }

  export = SortedArray;
}

I was struggling to figure out how I could write a type definition for passing an external/3rd party module around. I am very much not wise nor sharp with TypeScript, but TypeScript 2.9's import() syntax seems to be the answer I was looking for (after a long long long long amount of bumbling around, being misdirected):

declare type NewRelicModule = typeof import("newrelic");

Now I can write my:

interface Config {
  newrelic?: NewRelicModule;
}

It looks like you are expecting to use the default export. Perhaps for you this might work?

declare type SortedArray = typeof import("sorted-array").default;