R
R
Rustem2020-01-28 13:29:34
typescript
Rustem, 2020-01-28 13:29:34

How to declare a library function in JS in TypeScript?

I am writing a tool in TypeScript.
There was a need to use the library:
npm i ad

Types did not find it for it. Slowly I try to create for myself.
And I don’t understand how to declare functions of the form:

ad.user().get(filter)
await ad.user().get({fields: 'sAMAccountName'});

ad.user().add(options)
await ad.user().add({
    userName: 'jsmith'
    commonName: 'John Smith',
    password: '[email protected]!pt1'
});


In the declaration file:
export = ad;
declare class ad {
 user().get()???
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Robur, 2020-01-28
@h0kum

something like this:

user(): User

...

interface User {
   get(options: GetOptions): Promise<Something>
   add(options: AddOptions): Promise<SomethingElse>
}

Well and so on

S
Sun_Day, 2020-01-28
@Sun_Day

Read about Generics and questions will disappear by themselves. Google relevant articles or documentation: Here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question