获取:'string | undefined' 类型的参数不可分配给 'RequestInfo' 类型的参数
Fetch : Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'
我在获取函数的“fetchUrl”参数中收到以下错误
Argument of type 'string | undefined' is not assignable to parameter
of type 'RequestInfo'.
在这个函数中
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 函数中使用 any 数据类型来禁止类型检查。
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 => { .......
这是因为你的环境变量在你使用之前是未定义的。
对关键字使用类型断言:
as
所以像这样:
getBaseUrlNative( process.env.APP_DATA as string, ...)
这应该可以正常工作
我在获取函数的“fetchUrl”参数中收到以下错误
Argument of type 'string | undefined' is not assignable to parameter of type 'RequestInfo'.
在这个函数中
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 函数中使用 any 数据类型来禁止类型检查。
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 => { .......
这是因为你的环境变量在你使用之前是未定义的。
对关键字使用类型断言:
as
所以像这样:
getBaseUrlNative( process.env.APP_DATA as string, ...)
这应该可以正常工作