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

TypeScript support and ES6 #26

Open
blai30 opened this issue May 5, 2021 · 3 comments
Open

TypeScript support and ES6 #26

blai30 opened this issue May 5, 2021 · 3 comments

Comments

@blai30
Copy link

blai30 commented May 5, 2021

Are there any plans to add typings for use with TypeScript and/or ES6 modules (import/export)?

@Naramsim
Copy link
Member

Naramsim commented May 5, 2021

Not right now, To be honest, I don't know how to add the types.

About ES6 modules, the package.json should be modified? Right?

@blai30
Copy link
Author

blai30 commented May 5, 2021

I think package.json would have "type": "module" but I'm sure there is more to it than just that.

@mmethot
Copy link

mmethot commented Nov 19, 2022

For what it's worth, I got it working right out of the box with Typescript + Angular.

  1. I created a service file called pokedex.service.ts and added the PokeAPI wrapper in it:
import { Injectable } from '@angular/core';
import * as Pokedex from 'pokeapi-js-wrapper';

@Injectable({
  providedIn: 'root'
})

export class PokedexService {
  pokedex: Pokedex;

  constructor() {
    this.pokedex = new Pokedex.Pokedex();
  }

  async getPokemon() {
    const golduck = await this.pokedex.getPokemonByName("golduck");
    console.log(golduck);
  }
}
  1. I added my service file in my app.component.ts constructor:
constructor(private pokedexService: PokedexService) {
  ...
}
  1. I called the getPokemon method in the ngOnInit:
ngOnInit(): void {
  this.pokedexService.getPokemon();
}

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

No branches or pull requests

3 participants