Make typing of MakiObjects more explicit

This commit is contained in:
Jordan Eldredge 2019-10-14 08:52:25 -07:00
parent d215c619f1
commit a8df0dd575

View file

@ -287,9 +287,7 @@ function findDirectDescendantById<
);
}
function* iterateLexicalScope<
T extends { children: T[]; parent: T | undefined }
>(node: T): IterableIterator<T> {
function* iterateLexicalScope(node: MakiObject): IterableIterator<MakiObject> {
let currentNode = node;
while (currentNode.parent) {
const { parent } = currentNode;
@ -306,10 +304,10 @@ function* iterateLexicalScope<
}
// Search up the tree for a node that is in `node`'s lexical that matches `predicate`.
function findInLexicalScope<T extends { children: T[]; parent: T | undefined }>(
node: T,
predicate: (node: T) => boolean
): T | null {
function findInLexicalScope(
node: MakiObject,
predicate: (node: MakiObject) => boolean
): MakiObject | null {
for (const child of iterateLexicalScope(node)) {
if (predicate(child)) {
return child;