Learn, Share, Build

134
October 06, 2017, at 10:37 PM

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;
   }
}
READ ALSO
Learn, Share, Build

Learn, Share, Build

For some reason I can't scroll on a website that I am working onEventhough u see the scrollbar and u can drag it up and down

187
Learn, Share, Build

Learn, Share, Build

So i've got a dataset with movie ratings, each movie got multiple ratingsI managed to get all the data but i want to add all the values

179
Learn, Share, Build

Learn, Share, Build

I'm using Fixed-data-table in my react appI'm new to this concept Fixed-data-table

184