Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

js fetch with TS, is not assignable

$
0
0

Why I get this warning in TS ?

Type 'unknown' is not assignable to type 'PokemonList'.ts(2322)

This error is on line: "return e"

Code:

export interface PokemonList {  count: number;  next: string;  previous?: any;  results: {    name: string;    url: string;  }[]};const PokeApi = async (): Promise<PokemonList> => {  try {    const res = await fetch('https://pokeapi.co/api/v2/pokemon?limit=10');    return res.json()  } catch(e) {    return e;  }};

If I make this:

( Promise<PokemonList> | unknown )

then I get this error:

The return type of an async function or method must be the global Promise<T> type. Did you mean to write 'Promise<unknown>'?ts(

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>