Recursive interface declaration
Nice tool! However
interface StatsModel {
a: StatsModel
}
results in
function getParseTreeNode(node, nodeTest) { ^ RangeError: Maximum call stack size exceeded
Sorry, missed your issue. Yes, I didn't thought about recursive types. I can probably detect them but don't know how to serialize.
Had the same problem before: try this circular Replacer Or maybe this library
Hey, everyone.
I know this problem is very old, but I want to solve it because I think recursive types are quite common, especially in GraphQL applications.
@InsOpDe I tested the library you mentioned for a moment and I could see that it resolves a cyclic object. However, we need to take a step back and think about how to declare the reflected type using TypeScript factories in compile/transpile mode.
Personally, it's more complex to go the JSONPath way because I think it requires a big change to the codebase. But I can imagine a solution based on the OpenAPI's components schema using #/<typeName> as $ref, for example:
{
"root": {
"$ref": "#/StatsModel"
},
"types": {
"#/StatsModel": {
"kind": 19,
"name": "StatsModel",
"properties": {
"a": {
"kind": 19,
"modifiers": 0,
"$ref": "#/StatsModel"
}
}
}
}
}
What do you think?
CC: @goloveychuk
We have 3 options
- emit js code which references variables
- json schema
- custom schema with pathes
2 makes most sense, it's a standard and you can use ecosystem of libs, eg ajv. But then you will need to emit all types from project in one files, so you won't have duplicates if type is referencing other reflected type. But that's a big change and a lot of work.
That file will be "storage"
How this schema will be "storage"? Last week I tried to create a new SourceFile and import/require it while the code is built, but without success.