[英]Argument of type 'string | string[] | ParsedQs | ParsedQs[]' is not assignable to parameter of type 'string'
[英]Argument of type {…} is not assignable to parameter of type 'string | URL'
你能帮我解决我的代码中的错误吗? 我正在尝试将 Mailchimp 连接到我的应用程序,以便当用户使用 email 订阅时,它会直接添加到 Mailchimp 中的“受众”中。 我已经编写了代码,但是代码抱怨“选项”object。
import { request } from "http";
import { resolve } from "url";
import { response } from "express";
import { reject } from "lodash";
export async function keepSubscribers(email: string) {
const data = {
members: [
{
// eslint-disable-next-line @typescript-eslint/camelcase
email_address: email,
status: 'subscribed'
}
]
}
const postData = JSON.stringify(data)
const options = {
url: 'https://us20.api.mailchimp.com/3.0/lists/b0404295b1',
method: 'POST',
headers: {
Authorization: 'auth 71634e399a09a918610fd25094e6731c-us20'
},
body: postData
}
return new Promise((resolve, reject) => {
request(options: Object, (err: Object, response: { statusCode: number }) => {
if (err) {
return reject(`Request cannot be processed`);
} else {
if (response.statusCode === 200) {
return resolve(true)
} else {
return reject(`Request cannot be processed`);
}
}
})
})
}
尝试删除对request
的调用中的类型。
也就是说,替换这一行:
request(options: Object, (err: Object, response: { statusCode: number }) => {
有了这个:
request(options, (err: Object, response: { statusCode: number }) => {
由于 options 是在该行中作为参数传递的值(无需在那里声明)。
如果此更改后问题仍然存在,请指定有关它的其他一些详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.