Here are some tools for finding your way around.
Everything I have builds atop the existing Structure
interface and derived interfaces from ts-morph.
You can see at a glance the existing classes’ API on a per-class basis. The class API is necessarily tighter than the interface API, for several reasons.
The ts-morph project has a forEachStructureChild()
function, which works very well, as far as it goes.
Since type structures are very much an add-on to the structure hierarchy, I provide a forEachAugmentedStructureChild()
export with a similar API:
declare function forEachAugmentedStructureChild<
TStructure
>
(
structureOrArray: ArrayOrValue<StructureImpls | TypeStructures>,
callback: (child: StructureImpls | TypeStructures) => TStructure | void
): TStructure | undefined;
The rules for this function are pretty simple:
StructureImpl
, call forEachStructureChild()
first. If the return value is truthy, return that value.forEachStructureCHild()
may have missed. Return the first truthy value from the callback.
typeStructure
, returnTypeStructure
, implementsSet
, etc.In all cases, I prefer to visit structure classes before type structure classes.
Sorry, no. This is very much a shallow iterator. If ts-morph publishes documentation on a recursive version of forEachStructureChild()
, I will create a similar API for these structure classes.