'TypeScript creat recursive typing

Example because its not easy to explain

i need this to query data from database typeorm does not support it, so i need a way to generate cool typing, please help me

export class CategoryEntity {

  id: string;

  name: string;

  parentId?: CategoryEntity;
}


export class SpecialEntity {
  id: string;

  category: CategoryEntity;
}

resulting type should be

{ 
  id?: "ASC" | "DESC",
  category?: {
    id?: "ASC" | "DESC"
    name?: "ASC" | "DESC"
    parentId?: {
       id?: "ASC" | "DESC"
       name?: "ASC" | "DESC"
       parentId?: {
         ...
       }
    }
  }
}

should be used like

const order: OrderRelation<SpecificEntity> = {
  category: {
    parentId: {
      name: 'ASC'
    }
  }
}

Thx for helping me



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source