Skip to content

Generated types order and optional exports #665

@jeremymelchor

Description

@jeremymelchor

Let suppose I have those 2 schemas

example-ref-schema.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "$id": "example-ref",
  "properties": {
    "_id": {
      "type": "string"
    },
    "_key": {
      "type": "string"
    }
  },
  "required": ["_id", "_key"],
  "additionalProperties": false
}

example.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "allOf": [
    {
      "$ref": "./example-ref-schema.json"
    },
    {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        }
      },
      "required": ["name"],
      "additionalProperties": false
    }
  ]
}

It produces the following output:

example-ref-schema.d.ts

export interface ExampleRef {
  _id: string;
  _key: string;
}

example.d.ts

export type Example = ExampleRef & {
  name: string;
  description?: string;
};

export interface ExampleRef {
  _id: string;
  _key: string;
}

Is it possible to:

  1. have the ExampleRef interface declared before the ExampleWithArangoMetadata type ? I would like to generate Typebox types from this but the order creates an This variable is used before its declaration. error.
  2. Not having the ExampleRef interface from the schema.d.ts (and other schema files) exported but only the one from the example-ref-schema.d.ts ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions