gpt4 book ai didi

json - 使用 Typescript 进行持久化

转载 作者:太空宇宙 更新时间:2023-11-03 23:27:56 26 4
gpt4 key购买 nike

我目前正在使用 Electron(基本上是带有 chromium 的 Nodejs)和 Angular2 的项目

有什么方法可以将 typescript 对象保存在文件中吗?

目前,我将对象保存在 json 文件中。问题是所有对象方法都丢失了

我应该尝试保存 __proto__ 变量吗?

我应该使用框架还是特殊的数据库引擎?

今天我从 json 文件中读取对象并使用 JSON.parse 对其进行解析。然后我重新分配一个新对象中的所有属性,该对象不可扩展

欢迎任何建议

提前致谢。何塞

最佳答案

我是OP!

我刚刚发现这个库显然可以解决问题

https://www.npmjs.com/package/serializer.ts

So what to do? How to have in users array of User objects instead of plain javascript objects? Solution is to create new instances of User object and manually copy all properties to new objects.

Alternatives? Yes, you can use this library. Purpose of this library is to help you to map you plain javascript objects to the instances of classes you have created.

我会尝试并提供反馈。最好的

关于json - 使用 Typescript 进行持久化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41677412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com