Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postsvg: TS match and walk lack return-type annotation #132

Open
Ayc0 opened this issue Oct 27, 2021 · 0 comments
Open

postsvg: TS match and walk lack return-type annotation #132

Ayc0 opened this issue Oct 27, 2021 · 0 comments

Comments

@Ayc0
Copy link

Ayc0 commented Oct 27, 2021

When running the type check on my codebase, I have those 2 errors in postsvg:

node_modules/postsvg/postsvg.d.ts:74:5 - error TS7010: 'match', which lacks return-type annotation, implicitly has an 'any' return type.

74     match(expression: posthtml.Matcher, callback: (node: Node) => Node);
       ~~~~~

node_modules/postsvg/postsvg.d.ts:75:5 - error TS7010: 'walk', which lacks return-type annotation, implicitly has an 'any' return type.

75     walk(callback: (node: Node) => Node);
       ~~~~

This is because in postsvg.d.ts, there is no return type for both match and walk:

  class Tree extends Array {
    static createFromArray(array: Array): Tree;
    get root(): Node;
    toString(): string;
    clone(): Tree;
    match(expression: posthtml.Matcher, callback: (node: Node) => Node);
    walk(callback: (node: Node) => Node);
    select(selector: string): Node[];
    each(selector: string | TreeEachCallback, callack?: TreeEachCallback): Node[];
  }

An easy fix could be to do the following:

  class Tree extends Array {
    static createFromArray(array: Array): Tree;
    get root(): Node;
    toString(): string;
    clone(): Tree;
    match(expression: posthtml.Matcher, callback: (node: Node) => Node): void;
    walk(callback: (node: Node) => Node): void;
    select(selector: string): Node[];
    each(selector: string | TreeEachCallback, callack?: TreeEachCallback): Node[];
  }

But those 2 seems to be returning something (but I'm not sure what are the proper type)

Another easy fix could be:

  class Tree extends Array {
    static createFromArray(array: Array): Tree;
    get root(): Node;
    toString(): string;
    clone(): Tree;
    match(expression: posthtml.Matcher, callback: (node: Node) => Node): unknown;
    walk(callback: (node: Node) => Node): unknown;
    select(selector: string): Node[];
    each(selector: string | TreeEachCallback, callack?: TreeEachCallback): Node[];
  }

But this isn't ideal either.

I can do a PR if you want, but I don't know which type to choose 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant