如何在汽车应用中定义联合类型元数据

发布于 2025-01-30 03:32:02 字数 782 浏览 3 评论 0原文

我正在使用 automapper with pojo策略 我必须为此定义元数据,但是“邮政编码”字段具有联合类型。

      PojosMetadataMap.create<FrontendData>("FrontendData", {
        address: String,
        postalCode: null | number,
        latitude: Number,
        longitude: Number,
     });

不幸的是语法null邮政编码:null |数字不起作用。我已经看文档了,但是与此策略一起使用联合类型并没有什么可以 - htttps:htttps:// automapperts.netlify.app/docs/strategies/pojos/ 。 如果您解决了类似的问题,我会感谢您的帮助

I'm using automapper with Pojo strategy
I have to define metadata for it, but "postalCode" field have a union type.

      PojosMetadataMap.create<FrontendData>("FrontendData", {
        address: String,
        postalCode: null | number,
        latitude: Number,
        longitude: Number,
     });

Unfortunately the syntax null postalCode: null | number does not work. I have looking in documentation but there was nothing about using union types with this strategy - https://automapperts.netlify.app/docs/strategies/pojos/.
If you have solved a similar issue, I'd be thankful for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

治碍 2025-02-06 03:32:02

我在GitHub问题中问了同样的问题,并从图书馆的开发人员那里得到了答案:

迄今为止,没有工会支持元数据。数字|在这种情况下,零仍然是数字。如果源邮政编码为null,则将映射到null,如果源邮政编码未定义,则将映射到未定义的。如果源不确定

您可以找到GitHub问题在这里

I asked the same question in github issue and got an answer from the developer of the library:

As of the moment, there's no union support for metadata. number | null is still Number in this case. If the source postalCode is null then it will be mapped to null, if the source postalCode is undefined then it will be mapped to undefined. You can use undefinedSubstitution(null) to convert it to null if the source is undefined

You can find github issue here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文