提取:“字符串"类型的参数|未定义"不能分配给"RequestInfo"类型的参数 [英] Fetch : Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'

查看:55
本文介绍了提取:“字符串"类型的参数|未定义"不能分配给"RequestInfo"类型的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在"fetchUrl"中收到以下错误:fetch函数中的参数

'string |类型的参数未定义"不能分配给参数类型为"RequestInfo".

此功能

  let fetchUrl = getBaseUrlNative(process.env.APP_DATA,`/v2/marketing/app/file/$ {file}?cookies = $ {cookieSess}& expires = $ {Date.now()}`)等待fetch(fetchUrl,{方法:获取",缓存:无存储",标头:{'Cache-Control':'no-cache'}}).then(res => res.blob()).then(res => {....... 

getBaseUrlNative是

  export const getBaseUrlNative =(eUrl:字符串|未定义,ext:字符串|未定义)=>{尝试 {如果(!eUrl)抛出新的错误(``Error.'')返回分机?eUrl + ext:eUrl;} catch(err){console.log(err)}} 

解决方案

在fetch函数中使用 any 数据类型禁止类型检查.

 让fetchUrl = getBaseUrlNative(process.env.APP_DATA,`/v2/marketing/app/file/$ {file}?cookies = ${cookieSess}& expires = $ {Date.now()}`)等待fetch(< any> fetchUrl,{方法:获取",缓存:无存储",标头:{'Cache-Control':'no-cache'}}).then(res => res.blob()).then(res => {.......  

Im receiving the following error in the "fetchUrl" argument in the fetch function

Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'.

In this function

let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`)

    await fetch(fetchUrl, { method: 'get' , cache:"no-store" , headers: {
        'Cache-Control': 'no-cache'
      }})
         .then(res => res.blob())
         .then(res => {  .......

getBaseUrlNative is

export const getBaseUrlNative = (eUrl : string | undefined, ext : string | undefined) => {
    try {
        if (!eUrl) throw new Error("Error .")
        return ext ? eUrl+ext : eUrl;
    } catch (err) {
        console.log(err)
    }
}

解决方案

Use the any data type in the fetch function to disallow type checking.

let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`)

    await fetch(<any>fetchUrl, { method: 'get' , cache:"no-store" , headers: {
        'Cache-Control': 'no-cache'
      }})
         .then(res => res.blob())
         .then(res => {  .......

这篇关于提取:“字符串"类型的参数|未定义"不能分配给"RequestInfo"类型的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆