Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
There is a type error in the useSWR token delivery part

This error occurs after typescript is updated and the type is strict.



    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,
    }) 

After declaring the ProductInfo type, I put token and fetchWithToken functions in the api.

but ([/goods?lim=8, token], fetchWithToken, { dedupingInterval: 1000000, }) Here's the error with a red underline.

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)

I couldn't solve this problem, so I tried removing the ProductInfo type, but ProductDetail is not It is output as an unknown value.

how can i solve it? I do not know.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda