spectacles-ts
spectacles-ts copied to clipboard
Handle Recursive Interfaces
Closes https://github.com/anthonyjoeseph/spectacles-ts/issues/27
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 : falseis safe,Document extends A ? true : falseis not), we use a helper type calledB_extends_Athat is functionally equivalent and safe Pathsseems to work for types as complex asPaths<HTMLInputElement>, butPaths<Document>andPaths<Window>still crash- This is strange, because
HTMLInputElement["ownerDocument"]=Document. This simplifies toPath<{ ownerDocument: Document }>, which does compile - Next step is to dig into why
Paths<{ ownerDocument: Document }>cancels recursion 'better' thanPaths<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 }
- I suspect it's some implementation error with
- 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 -
Pathsis only calling itself 5 or 6 times deep, far from the 1000-deep limit. Nothing else is recursive - could it be because
Documentis 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?
- I don't think it's type instantiation depth -