colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.09k stars 1.15k forks source link

`z.ref` #3715

Open sheepbox8646 opened 1 month ago

sheepbox8646 commented 1 month ago

There is a special usage in JSON Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "root": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "arguments": {
          "type": "array"
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/properties/root"
          }
        },
      }
    }
  },
  "required": [
    "root"
  ]
}

$ref means use a defined structure in the tree.

Have zod a similar function or not? If not, there is any posibility add it?

I try to use a defined structure in Zod, but the ts-server says the types are loop used