So I have recently converted a ReactJs project from ES6 JavaScript to TypeScript and had a wave of errors that I had to work through. One of the final errors that occurs and I cannot seem to find a fix for it for the section of code
async componentDidMount() {
const { pokemonIndex } = this.props.match.params;
// Urls for pokemon information
const pokemonUrl = `https://pokeapi.co/api/v2/pokemon/${pokemonIndex}/`;
const pokemonSpeciesUrl = `https://pokeapi.co/api/v2/pokemon-species/${pokemonIndex}/`;
// Get Pokemon Information
const pokemonRes = await axios.get(pokemonUrl);
const name = pokemonRes.data.name;
const imageUrl = pokemonRes.data.sprites.front_default;
let { hp, attack, defense, speed, specialAttack, specialDefense }: any = "";
pokemonRes.data.stats.map(
(stat: { [x: string]: any; stat: { name: any } }) => {
switch (stat.stat.name) {
case "hp":
hp = stat["base_stat"];
break;
case "attack":
attack = stat["base_stat"];
break;
case "defense":
defense = stat["base_stat"];
break;
case "speed":
speed = stat["base_stat"];
break;
case "special-attack":
specialAttack = stat["base_stat"];
break;
case "special-defense":
specialDefense = stat["base_stat"];
break;
default:
break;
}
}
);
And more specifically on the line
const { pokemonIndex } = this.props.match.params;
What is the reason for this?
----------------EDIT----------------------------------
The code below is that of my App.tsx with the routing I've used
import React, { Component } from "react";
import "./App.css";
import NavBar from "./components/layout/NavBar";
import "bootstrap/dist/css/bootstrap.min.css";
import "./App.css";
import Dashboard from "./components/layout/Dashboard";
import { HashRouter as Router, Route, Switch } from "react-router-dom";
import Pokemon from "./components/pokemon/Pokemon";
class App extends Component {
constructor() {
super({});
this.state = {};
}
render() {
return (
<Router>
<div className="App">
<NavBar />
<div className="container">
<Switch>
<Route exact path="/" component={Dashboard} />
<Route exact path="/pokemon/:pokemonIndex" component={Pokemon} />
<Dashboard />
</Switch>
</div>
</div>
</Router>
);
}
}
export default App;