Typescript definition file for scripting host inside desktop application without webframework

40 views Asked by At

I am trying to create a typescript definition file for a javascript for use in a desktop application. I am interested in the intellisense feature of typescript.

The environment where the javascript file is being run is inside another desktop application using the windows scripting host. I have access to the desktop application vendor's documentation (including the objects and functions and their relation), but not the source code. I am using Visual Studio 2017 to code the javascript(Jscript) files.

The desktop application is exposing it's API as members of the Class Application to the script, including the member document (like a webbrowser, but with different methods and properties).

An example og the object relationships is as follows:

Application            (class cvAppOld)
-> Document            (class cvDoc)        (accessed by 'document')
   -> Table            (class cvTable)      (accessed by 'document.getTable()')
   -> Paragraph        (class cvPara)       (accessed by 'document.getPara()')
-> ApplicationSettings (class cvAppSetting) (accessed by 'settings')

As per the developer documentation:

The application object is the main object. All of its properties and methods can be accessed locally in the scripting environment.

An example of a script file 'somefile.js':

function sortTable("sometablename") {
   var table = document.getTable("sometablename");
   table.autosort = 1;
   table.update;
   document.save;
}

I am unclear as to where I should begin writing the definitions. I guess I have to create a file called 'index.d.ts' in the same folder as the javascript file - right?

All the examples that I can find on the web, describes how to do this when using NPM or using 'import' in a javascript projectfile. I have none of the above. The javascript file is only a single file without includes, in which the desktop application runs a function.

I am trying to use this as a starting point: https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-d-ts.html, but cannot seem to make any headway.

Someplaces the examples use export and other places declare, and on different levels. I can't seem to grasp the connection. Am I just dumb? :)

So far I have this in index.d.ts:

declare namespace Something {
   class CvDoc {
      getPara(Index: number): CvPara;
      getTable(Index: number): CvTable;
   }
   class cvPara {
      someProperty: any;
   }
   class cvTable {
      someProperty: any;
   }
   class cvAppSettings {
      someProperty: any;
   }
}
0

There are 0 answers