Trying to create a .D.TS file based on custom API library

23 Views Asked by At

So, I work on platform that leverages it's own OOP API library based on JavaScript. The main object is called "controller" and is passed in a functioned called "run". From there we use the controller object to access other methods that return objects, booleans, strings, numbers, nothing.


var c; //global

function run(controller){
c=controller //makes it easier

var page = c.getPage("index"); //gets the named HTML page and returns it as an object
page.setValue("name","value); //sets a value on the page object
return page; //returns the page

}

Documentation for these methods looks like this...

getPage(String page) Returns the specified page.

setValue(String key, String value) Adds the key/value pair to the data object for this page, over-writing any set that already exists with name key. Shortcut for getData().setValue(key,value)

The goal here is to create a d.ts file that we can use in vscode to leverage intellisense to assist developers. I've never created a d.ts file before, and am looking for an example of what that file would look like based on what I shared above, so I have a starting point that will work.

EDIT: I've made some progress on this!

I've got the following in my index.d.ts file now.

    export class controller{
    debug(msg:string):null;
    createData(name:string):data;
    createEmail(name:string):email;
}

export class email{
    addData(data:data):void;
    setValue(name:string, value:string):void;
    setBoolean(name:string, value:boolean):void;
}

export class data{
    addData(data:data):void;
    setValue(name:string, value:string):void;
    setBoolean(name:string, value:boolean):void;
}

I can verify that VSCode is finding my .d.ts file and it is validating the entries as I type. And after I enter "()" it shows a popup of what is expected for that method. However, I thought Intellisense helped with autocomplete too, where I didn't have to type out the whole name of the method. What am I missing?

0

There are 0 best solutions below