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

export all interfaces instead of just the 'top' interface #15

Closed
hemmoleg opened this issue Dec 14, 2021 · 4 comments
Closed

export all interfaces instead of just the 'top' interface #15

hemmoleg opened this issue Dec 14, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@hemmoleg
Copy link

Hey,

could you change all the .d.ts files to export all interfaces? There are two reasons why I think this would be a good change:

  1. you could go from this: foo(match.info : any) to foo(match.info : Info) This has two advantages: first type safety and second enabling auto complete for the properties of Info in the method. I know you could also just always pass the entire match to any function. however i think thats kind of unnecessary.
  2. you could create a variable in a type safe way without having to define them right away. So instead of let matchInfo: any; you could write matchInfo : Info; This comes with the same adantages as the first reason.
@b-cho b-cho added the enhancement New feature or request label Dec 15, 2021
@b-cho
Copy link
Owner

b-cho commented Dec 25, 2021

Hello @hemmoleg!

I believe that the DTOs for request responses should already be available for use. (Potentially redefining type Info = Galeforce.dto.MatchDTO['info']; could help?)

Code example:

import Galeforce from 'galeforce';

const galeforce = new Galeforce({
  'riot-api': {
    key: 'RGAPI-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
  },
});

type Info = Galeforce.dto.MatchDTO['info'];

(async () => {
  const matchInfo: Info = (await galeforce.lol.match.match()
    .region(galeforce.region.riot.AMERICAS)
    .matchId('NA1_1234567890')
    .exec()).info;
  console.log(matchInfo);
})();

Please let me know if this works for you!

@hemmoleg
Copy link
Author

hemmoleg commented Jan 2, 2022

Hello bcho04,

thank you very much for your answer. that does indeed work for me. However it still seems like kind of a hack, so just out of curiosity: why dont you just export the other interfaces as well?

@b-cho
Copy link
Owner

b-cho commented Jan 5, 2022

@hemmoleg

There are a couple reasons why I'm currently not exporting all of the lower-level interfaces for the DTOs; there's some name collision with the actual interface names, they're accessible as properties of the top-level interfaces corresponding to the API return values, and the sheer number of them (and their internal nature) makes it somewhat messy to export all of them directly.

@hemmoleg
Copy link
Author

oh ok. well thank you for the explanation :)

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

No branches or pull requests

2 participants