• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

123
Views
Hay un error de tipo en la parte de entrega del token useSWR

Este error ocurre después de que se actualiza el mecanografiado y el tipo es estricto.

 const token = 'aaa' const fetchWithToken = (url: string, token: string) => axios.get(url, { headers: { Authorization: `Bearer ${token}`, }, withCredentials: true }) .then(result => result.data); const { data: ProductDetail } = useSWR<ProductInfo>([`/goods?lim=8`, token], fetchWithToken, { dedupingInterval: 1000000, })

Después de declarar el tipo ProductInfo, puse las funciones token y fetchWithToken en la API.

pero ([ /goods?lim=8 , token], fetchWithToken, { dedupingInterval: 1000000, }) Aquí está el error subrayado en rojo.

 Argument of type '[string[], (url: string, token: string) => Promise<unknown>, { dedupingInterval: number; }]' is not assignable to parameter of type 'readonly [Key] | readonly [Key, Fetcher<ProductInfo> | null] | readonly [Key, Partial<PublicConfiguration<ProductInfo, any, Fetcher<ProductInfo>>> | undefined] | readonly [...]'. Type '[string[], (url: string, token: string) => Promise<unknown>, { dedupingInterval: number; }]' is not assignable to type 'readonly [Key, Fetcher<ProductInfo> | null, Partial<PublicConfiguration<ProductInfo, any, Fetcher<ProductInfo>>> | undefined]'. Type at position 1 in source is not compatible with type at position 1 in target. Type 'Promise<unknown>' is not assignable to type 'ProductInfo | Promise<ProductInfo>'. Type 'Promise<unknown>' is not assignable to type 'Promise<ProductInfo>'. Type 'unknown' is not assignable to type 'ProductInfo'.ts(2345)

No pude resolver este problema, así que intenté eliminar el tipo ProductInfo, pero ProductDetail no se muestra como un valor desconocido.

¿Cómo puedo resolverlo? No sé.

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error