blackflux / object-treeify

Stringify Object as tree structure
MIT License
16 stars 5 forks source link

Typescript types are needed #1077

Open ThePlenkov opened 1 year ago

ThePlenkov commented 1 year ago

Hi!

For such a code:

import * as t from 'object-treeify';

I have an error:

Could not find a declaration file for module 'object-treeify'. '/workspaces/wikify-example/node_modules/object-treeify/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/object-treeify` if it exists or add a new declaration (.d.ts) file containing `declare module 'object-treeify';`

Is there any module which has types?

Thanks!

lmcsu commented 8 months ago

Create env.d.ts file at the root of your project and put something like this into there

declare module 'object-treeify' {
    export type Node = Tree | boolean | string | number | null | undefined;

    export type Tree = {
        [key: string]: Node;
    };

    export type Options = {
        joined?: boolean;
        spacerNoNeighbour?: string;
        spacerNeighbour?: string;
        keyNoNeighbour:? string;
        keyNeighbour:? string;
        separator:? string;
        renderFn?: (node: Node) => boolean | undefined;
        sortFn?: ((a: string, b: string) => number) | null;
        breakCircularWith?: string | null;
    };

    function F(tree: Tree, options?: Options): string;

    export = F;
}