wix-events-backend的createEvent()传入eventInfo参数报错如何解决
Wix Events createEvent 类型错误解决方案
错误原因
你传入的eventInfo对象属性名与WixEventInfo类型要求不匹配:你当前使用的location、scheduling属性是旧版命名,新版API要求对应属性名为locationInfo、schedulingInfo,这就是报错提示缺少这两个属性的原因。
修正后的完整代码
import { wixEvents } from "wix-events-backend"; const eventInfo = { title: "Healthy Living Series: Exercise and You", // 把原来的location改为locationInfo locationInfo: { name: "Community Hall", address: { formatted: "100 Gansevoort St, New York, NY 10014, USA", city: "New York City", subdivision: "New York", country: "USA", postalCode: "10014", streetAddress: { number: "100", name: "Gansevoort Street", apt: "10" } }, type: 'VENUE', }, // 把原来的scheduling改为schedulingInfo schedulingInfo: { startDate: "2021-09-14T13:30:00.000Z", endDate: "2021-09-14T15:30:00.000Z", timeZoneId: "America/New_York" }, registration: { initialType: 'RSVP' } }; const options = { language: "en" }; export function myCreateEventFunction() { return wixEvents.createEvent(eventInfo, options) .then((result) => { return result; }) .catch((error) => { console.error(error); }); }
额外注意事项
- 该命名调整是Wix Events后端API的新版规范,旧版文档的示例未更新才会导致该问题
- 确保项目依赖的
wix-events-backend模块为最新版本,避免出现其他版本兼容问题 - 运行测试时可打印返回的result对象,确认活动ID、状态等返回字段是否符合预期
内容的提问来源于stack exchange,提问作者Q A
相关产品推荐
相关产品推荐

