spectacles-ts icon indicating copy to clipboard operation
spectacles-ts copied to clipboard

Handle Recursive Interfaces

Open anthonyjoeseph opened this issue 3 years ago • 1 comments

Closes https://github.com/anthonyjoeseph/spectacles-ts/issues/27

anthonyjoeseph avatar Apr 11 '22 14:04 anthonyjoeseph

Progress report:

  • basic method is to track all parent interfaces for each path, and if a parent extends its child, break the recursion
  • Since we can't put the original type in the 'check' type (A extends Document ? true : false is safe, Document extends A ? true : false is not), we use a helper type called B_extends_A that is functionally equivalent and safe
  • Paths seems to work for types as complex as Paths<HTMLInputElement>, but Paths<Document> and Paths<Window> still crash
  • This is strange, because HTMLInputElement["ownerDocument"] = Document. This simplifies to Path<{ ownerDocument: Document }>, which does compile
  • Next step is to dig into why Paths<{ ownerDocument: Document }> cancels recursion 'better' than Paths<Document>
    • I suspect it's some implementation error with B_extends_A
    • pin down which path(s) are being 'broken' by the parent type { ownerDocument: Document }
  • Alternately, continue to investigate the boundary of types that crash - what does 'better' recursion cancellation mean?
    • I don't think it's type instantiation depth - Paths is only calling itself 5 or 6 times deep, far from the 1000-deep limit. Nothing else is recursive
    • could it be because Document is so wide? (i.e. has so many keys - as opposed to 'deep')
    • if width is an issue, maybe consider rejecting recursive types altogether
      • is 'detecting' recursive types less complex than 'handling' them?

anthonyjoeseph avatar Apr 28 '22 00:04 anthonyjoeseph