0
votes

I am building a rest api using loopback.js I recenntly discovered this npm resource. So I went ahead and installed these types in my project.

But either I am missing something or these types have problems. My intellisense does not show me everything. Let me illustrate with an example.

First here is a sample definition of the PersistedModel from the index.d.ts:

class PersistedModel extends Model {

     static count(where?: any, callback?: (err: Error, count: number) => void): void;

     static find(
                  filter?: {fields?: string|any|any[]; 
                  include?: string|any|any[]; limit?: number; order?: string; 
                  skip?: number; where?: any; },
                  callback?: (err: Error, models: any[]) => void): void;    
}

Now let say I define a variable myModel of type PersistedModel

var myModel:PersistedModel = some_value;

(some_value is also of type PersistedModel)

When I write myModel., I would expect visual studio code to display the available list of all methods and properties of PersistedModel

Instead there are some methods although clearly defined in the index.d.ts file which do not appear in the dropdown list from intellisense. In the above example, the find method is missing from the intellisense dropdown list

Is this a bug in vscode? a poorly generated typings from the loopback or am I doing something wrong with my setup (typescript, vscode).

Has any body being able to write loopback application with typescript? Is there any documentation with best practices?

Thank you for your attention and your help

1

1 Answers

1
votes

The methods that do not appear in the dropdown are marked as static. The myModel variable you have is an instance of PersistedModel so it will list only instance methods. If you want to access the static methods use the class reference PersistedModel.find instead of the instance variable myModel.