Skip to content

Minor type adjustments for all() and children #86

@daKmoR

Description

@daKmoR

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch tree-model@1.0.7 for the project I'm working on.

  1. Allow usage of node.all() which currently throws a typing error as it always expects at least 1 option
  2. Type node.children so when iterating you do not get a typing error

Here is the diff that solved my problem:

diff --git a/node_modules/tree-model/types/index.d.ts b/node_modules/tree-model/types/index.d.ts
index 6f102c9..6ef264f 100644
--- a/node_modules/tree-model/types/index.d.ts
+++ b/node_modules/tree-model/types/index.d.ts
@@ -27,7 +27,7 @@ declare namespace TreeModel {
         walk(options: Options, fn: NodeVisitorFunction<T>, ctx?: object): void;
         walk(fn: NodeVisitorFunction<T>, ctx?: object): void;
 
-        all(options: Options, fn: NodeVisitorFunction<T>, ctx?: object): Array<Node<T>>;
+        all(options?: Options, fn?: NodeVisitorFunction<T>, ctx?: object): Array<Node<T>>;
         all(fn: NodeVisitorFunction<T>, ctx?: object): Array<Node<T>>;
 
         first(options: Options, fn: NodeVisitorFunction<T>, ctx?: object): Node<T> | undefined;
@@ -36,6 +36,7 @@ declare namespace TreeModel {
         drop(): Node<T>;
 
         [propName: string]: any;
+        children?: Array<Node<T>>
     }
 
     interface Config {

This issue body was partially generated by patch-package.

Would you like to have a PR for that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions