Javascript Fetch:类型为';字符串|未定义';不可分配给类型为';请求信息';
我在fetch函数的“fetchUrl”参数中收到以下错误 “string | undefined”类型的参数不可分配给参数 类型为“RequestInfo” 在这个函数中Javascript Fetch:类型为';字符串|未定义';不可分配给类型为';请求信息';,javascript,typescript,fetch,Javascript,Typescript,Fetch,我在fetch函数的“fetchUrl”参数中收到以下错误 “string | undefined”类型的参数不可分配给参数 类型为“RequestInfo” 在这个函数中 let fetchUrl = getBaseUrlNative( process.env.APP_DATA, `/v2/marketing/app/file/${file}?cookies=${cookieSess}&expires=${Date.now()}`) await fetch(fetchUrl,
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是
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)
}
}
在fetch函数中使用任何数据类型来禁止类型检查
let fetchUrl=getBaseUrlNative(process.env.APP_DATA,`/v2/marketing/APP/file/${file}?cookies=${cookiesses}&expires=${Date.now()}`)
等待获取(fetchUrl,{method:'get',缓存:“no store”,标题:{
“缓存控制”:“无缓存”
}})
.then(res=>res.blob())
.然后(res=>{……