type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

Paths<T> should handle recursive types

Open Xriuk opened this issue 1 month ago • 0 comments

Currently Paths<T> does not handle types like this (translation of some backend DB entities):

type MyEntity ={
   myOtherEntity: MyOtherEntity;
    ...
}

type MyOtherEntity ={
    myEntity: MyEntity;
    ...
}

type MyEntityPaths = Paths<MyEntity>;

TS gives an error like this: The type of property ... circularly references itself in mapped type ...

The main issue here would be determining if any given type recurses, which would require comparing already entered types (which afaik is unfeasible). A possible solution would be adding an optional "hard limit" of depth parameter, which won't go beyond N levels deep. In this case also types using Paths<T> like PickDeep should include this parameter and forward it to Paths<T>.

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

Xriuk avatar May 15 '24 13:05 Xriuk