我正在开发一个 Nest.js 服务器,并希望能够在控制台(例如 console.log)中打印有用的堆栈跟踪。默认情况下,它返回对编译源 (.js) 中行号的引用。这对调试没有用,因为它缺少对原始源文件 (.ts) 中行号的引用
这是我的 tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"_baseUrl": "./",
"incremental": true
},
"exclude": ["node_modules", "dist"]
}
Run Code Online (Sandbox Code Playgroud)
.map 文件也在 dist 文件夹中生成,尽管在控制台中检查堆栈跟踪时它似乎没有用。
我正在寻找一种简单的方法来直接将 python 字典转换为自定义对象,如下所示,同时不破坏智能感知。结果不应该是只读的,它的行为应该就像一个新对象。
d = {
"key1": 1,
"key2": 2
}
class MyObject(object):
key1 = None
key2 = None
# convert to object o
# after conversion
# should be able to access the defined props
# should be highlighted by intellisense
print(o.key1)
# conversion back to dict is plain simple
print(o.__dict__)
Run Code Online (Sandbox Code Playgroud)