Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: Simple Typescript usage example #384

Closed
alaincao opened this issue Jul 8, 2019 · 15 comments
Closed

Documentation: Simple Typescript usage example #384

alaincao opened this issue Jul 8, 2019 · 15 comments
Labels

Comments

@alaincao
Copy link

alaincao commented Jul 8, 2019

Description
Heylow, I'd like to have a simple example on where I can find the types returned by the different functions. e.g.

import * as gitlab from 'gitlab'
const aaa = new gitlab.Gitlab({ host:'foo', token:'bar' });
const bbb : WHAT_AM_I??? = aaa;

The thing is that I would like to pass them to e.g. a function, and for now I am using any where the WHAT_AM_I??? is, but that kinda defeats the purpose ...
I am hitting a wall for days, here ; I have a hint with the

import * as APIServices from 'gitlab/dist/services';

I saw in issue # 257, but still, no idea how to use ...

Proposal
I'd love to find a simple example e.g. in the Readme.md file or somewhere easily reachable ...

Thanks !

@jdalrymple
Copy link
Owner

Ill throw something together in the next couple days!

@jdalrymple
Copy link
Owner

So I haven't been able to get around to this. If anyone has time this would be a good first issue!

@ksaaskil
Copy link
Contributor

I was able to infer the type of new Gitlab(...) with following:

type ConstructedType<Constructor> = Constructor extends {
  new (...args: any[]): infer B;
}
  ? B
  : never;

type GitlabType = ConstructedType<typeof Gitlab>;

If that looks good, I can add a PR to add that in documentation and/or export the types for easier access?

@ksaaskil
Copy link
Contributor

ksaaskil commented Aug 21, 2019

No wait I'm dumb, one can use the built-in InstanceType:

type Gitlab = InstanceType<typeof Gitlab>;

@Bauke
Copy link

Bauke commented Aug 29, 2019

Although probably a rather big job, would it be possible to also get proper types for the responses to API calls?

For example calling Projects.show() returns a Promise<GetResponse>. If I then wanted to get the project ID or anything else that does in fact exist on the result, TypeScript will error out and say it doesn't exist on the GetResponse type (which would be correct):

source/edit-label.ts:24:48 - error TS2339: Property 'id' does not exist on type 'GetResponse'.
  Property 'id' does not exist on type 'object'.

24     log((await api.Projects.show(projectName)).id);

Only by casting it to a type you made yourself with the right properties or any can you then access it:

    log((await api.Projects.show(projectName) as any).id);

@jdalrymple
Copy link
Owner

@Bauke Eventually thats the plan, by pulling the information straight from gitlab's docs. #104 but until the expose proper api docs, its going to be a little difficult :(

Granjow added a commit to Granjow/node-gitlab that referenced this issue Nov 14, 2019
This commit also introduces a minimal typed response as a first step
towards jdalrymple#384.
Granjow added a commit to Granjow/node-gitlab that referenced this issue Nov 20, 2019
This commit also introduces a minimal typed response as a first step
towards jdalrymple#384.
jdalrymple pushed a commit that referenced this issue Nov 20, 2019
This commit also introduces a minimal typed response as a first step
towards #384.
jdalrymple pushed a commit that referenced this issue Nov 20, 2019
# [11.6.0](11.5.1...11.6.0) (2019-11-20)

### Features

* Add Group.projects ([#494](#494)) ([9def4e7](9def4e7)), closes [#384](#384)
@Telokis
Copy link

Telokis commented Mar 17, 2020

What is missing in order for us to have proper typings for MergeRequests?

@jdalrymple
Copy link
Owner

A chunk is already supported, but i need to finally merge some of the PR's. Im just waiting on the first release of the latest version of the library before doing so and THATS being held up by finishing the automatic release pipeline with semantic-release-npmx. Almost there, just been a crazy couple months :/

@Granjow
Copy link
Contributor

Granjow commented May 12, 2020

For a while now all Typing support has gone and the types file lists that:

export declare const Groups: any, GroupAccessRequests: any, GroupBadges: any, GroupCustomAttributes: any, GroupIssueBoards: any // etc.

Are the types (which are still supported in the original gitlab package) going to come back?

@jdalrymple
Copy link
Owner

They should be! Ill look into it, sorry about that :/

@jdalrymple
Copy link
Owner

@Granjow , continuing the conversation in #793

@simpsamu
Copy link

This is tremendously important .

@jdalrymple
Copy link
Owner

For a while now all Typing support has gone and the types file lists that:

export declare const Groups: any, GroupAccessRequests: any, GroupBadges: any, GroupCustomAttributes: any, GroupIssueBoards: any // etc.

Are the types (which are still supported in the original gitlab package) going to come back?

This should be fixed now

@jdalrymple
Copy link
Owner

What is missing in order for us to have proper typings for MergeRequests?

This have also been released

@jdalrymple
Copy link
Owner

Closing in favour of #492

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants