我遇到了 Typescript 的问题,因为它不允许我在没有内容字段的情况下构建电子邮件。 MailDataRequired
正确吗?
我从来没有用我的电子邮件发送内容。 只能换人。 内容/模板存在于您的服务器上。
export type MailDataRequired = MailData & (
{ text: string } | { html: string } | { templateId: string } | { content: MailContent[] & { 0: MailContent } });
# paste exception/log here
顺便说一句:6.5.0 似乎没有这个奇怪的{ 0: MailContent }
要求,但仍然需要内容。
也在看这个。 更新了我的包,现在不确定这个
考虑到这是https://github.com/sendgrid/sendgrid-nodejs/issues/1056的副本,除非我弄错了。
text
、 html
或content
。 后来有人指出templateId
本身也应该被允许。 这已作为部分 #1053 修复,但尚未发布。@childish-sambino 这仍然是6.5.4
的问题,类型定义如下:
type MailDataRequired = MailData & (
{ text: string } | { html: string } | { content: MailContent[] & { 0: MailContent } });
这使content
成为必需属性,当MailData
将其定义为条件属性时是否有理由? 我通过传递来修复它:
{...mailData, content: undefined}
6.5.4 版本中引入的 1041 需要
text
、html
或content
。
@rodrigomf24 mailData
没有其中之一吗?
@childish-sambino 不只是templateId
和dynamicTemplateData
@rodrigomf24
后来指出也应该允许 templateId 本身。 这已作为部分 #1053 修复,但尚未发布。
这个补丁发布了吗?
我刚拿到 7.0.0 版,但仍然看到此错误
TSError: ⨯ Unable to compile TypeScript:
src/email-templates/verification-email-template.ts(15,25): error TS2769: No overload matches this call.
Overload 1 of 2, '(data: MailDataRequired, isMultiple?: boolean | undefined, cb?: ((err: Error | ResponseError, result: [ClientResponse, {}]) => void) | undefined): Promise<...>', gave the following error.
如果这在 7.0.0 中发生了变化,请问发送 api 的最新文档在哪里? 在这里找不到太多。 @childish-sambino
谢谢。
是的,这是在6.5.5中发布的
@childish-sambino 你对从@sendgrid/mail
包中导出MailDataRequired
什么看法?
@isaachinman我没有问题。 如果你想提交 PR,我可以查看它。
@幼稚-萨比诺我周围一看,和我不熟悉的模块方式export =
正在采取这里。 我不清楚如何在不引入破坏性更改的情况下扩展它。
如果你能指出我正确的方向,我很乐意提供帮助。
认为这一行可以更新: https :
像这样也许:
declare const mail: MailService & { MailService: typeof MailService, MailDataRequired: typeof MailDataRequired };
不,这不起作用,因为MailDataRequired
已经是一种类型。 declare const
使事情变得有些复杂。
然后只是, MailDataRequired: MailDataRequired };
?
不,我要说的是字面上向默认导出添加了MailDataRequired
属性。 如果您尝试了最新的建议,则会收到refers to a value, but is being used as a type
错误。
我还没有看到任何其他使用这种模块方法管理类型的包,所以我无法真正为您提供任何建议。 您需要一种支持命名导出的方法。
通常我希望看到这样的事情:
export default mail
export { MailDataRequired }
@isaachinman认为这个(hack)应该修复它: https :
最有用的评论
顺便说一句:6.5.0 似乎没有这个奇怪的
{ 0: MailContent }
要求,但仍然需要内容。