zrwusa / data-structure-typed

Javascript Data Structure & TypeScript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree, AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack.
https://data-structure-typed-docs.vercel.app
MIT License
132 stars 9 forks source link

Type error after upgrading to 1.53.9 #117

Closed snakamura closed 1 week ago

snakamura commented 1 week ago

Hi, I got these type errors after upgrading to 1.53.9. Do you have any ideas?

node_modules/data-structure-typed/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts:159:5 - error TS2416: Property 'clone' in type 'AVLTreeMultiMap<K, V, R, NODE>' is not assignable to the same property in base type 'AVLTree<K, V, R, NODE>'.
  Type '() => AVLTreeMultiMap<K, V, R, NODE>' is not assignable to type '() => this'.
    Type 'AVLTreeMultiMap<K, V, R, NODE>' is not assignable to type 'this'.
      'AVLTreeMultiMap<K, V, R, NODE>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'AVLTreeMultiMap<K, V, R, NODE>'.

159     clone(): AVLTreeMultiMap<K, V, R, NODE>;
        ~~~~~

node_modules/data-structure-typed/dist/mjs/data-structures/binary-tree/bst.d.ts:162:5 - error TS2416: Property 'createTree' in type 'BST<K, V, R, NODE>' is not assignable to the same property in base type 'BinaryTree<K, V, R, NODE>'.
  Type '(options?: BSTOptions<K, V, R>) => BST<K, V, R, BSTNode<K, V, BSTNodeNested<K, V>>>' is not assignable to type '(options?: BinaryTreeOptions<K, V, R>) => this'.
    Type 'BST<K, V, R, BSTNode<K, V, BSTNodeNested<K, V>>>' is not assignable to type 'this'.
      'this' could be instantiated with an arbitrary type which could be unrelated to 'BST<K, V, R, BSTNode<K, V, BSTNodeNested<K, V>>>'.

162     createTree(options?: BSTOptions<K, V, R>): BST<K, V, R, BSTNode<K, V, BSTNodeNested<K, V>>>;
        ~~~~~~~~~~

node_modules/data-structure-typed/dist/mjs/data-structures/binary-tree/bst.d.ts:418:5 - error TS2416: Property 'map' in type 'BST<K, V, R, NODE>' is not assignable to the same property in base type 'BinaryTree<K, V, R, NODE>'.
  Type '<MK, MV, MR>(callback: EntryCallback<K, V, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any) => BST<MK, MV, MR, BSTNode<...>>' is not assignable to type '<MK, MV, MR>(callback: EntryCallback<K, V, [MK, MV]>, options?: BinaryTreeOptions<MK, MV, MR>, thisArg?: any) => BinaryTree<MK, MV, MR, BinaryTreeNode<...>>'.
    Call signature return types 'BST<MK, MV, MR, BSTNode<MK, MV, BSTNodeNested<MK, MV>>>' and 'BinaryTree<MK, MV, MR, BinaryTreeNode<MK, MV, BinaryTreeNodeNested<MK, MV>>>' are incompatible.
      The types of 'search' are incompatible between these types.
        Type '<C extends NodeCallback<BSTNode<MK, MV, BSTNodeNested<MK, MV>>>>(keyNodeEntryRawOrPredicate: MR | Range<MK> | BTNRep<MK, MV, BSTNode<MK, MV, BSTNodeNested<...>>> | NodePredicate<...>, onlyOne?: boolean, callback?: C, startNode?: MR | BTNRep<...>, iterationType?: IterationType) => ReturnType<...>[]' is not assignable to type '<C extends NodeCallback<BinaryTreeNode<MK, MV, BinaryTreeNodeNested<MK, MV>>>>(keyNodeEntryRawOrPredicate: MR | BTNRep<MK, MV, BinaryTreeNode<...>> | NodePredicate<...>, onlyOne?: boolean, callback?: C, startNode?: MR | BTNRep<...>, iterationType?: IterationType) => ReturnType<...>[]'.
          Types of parameters 'keyNodeEntryRawOrPredicate' and 'keyNodeEntryRawOrPredicate' are incompatible.
            Type 'MR | BTNRep<MK, MV, BinaryTreeNode<MK, MV, BinaryTreeNodeNested<MK, MV>>> | NodePredicate<BinaryTreeNode<MK, MV, BinaryTreeNodeNested<...>>>' is not assignable to type 'MR | Range<MK> | BTNRep<MK, MV, BSTNode<MK, MV, BSTNodeNested<MK, MV>>> | NodePredicate<BSTNode<MK, MV, BSTNodeNested<...>>>'.
              Type 'BinaryTreeNode<MK, MV, BinaryTreeNodeNested<MK, MV>>' is not assignable to type 'MR | Range<MK> | BTNRep<MK, MV, BSTNode<MK, MV, BSTNodeNested<MK, MV>>> | NodePredicate<BSTNode<MK, MV, BSTNodeNested<...>>>'.
                Type 'BinaryTreeNode<MK, MV, BinaryTreeNodeNested<MK, MV>>' is not assignable to type 'BSTNode<MK, MV, BSTNodeNested<MK, MV>>'.
                  The types of 'parent.parent.parent.parent.parent.parent.parent.parent.parent.parent' are incompatible between these types.
                    Type 'BinaryTreeNode<MK, MV, any>' is not assignable to type 'BSTNode<MK, MV, any>'.
                      Property '_left' is protected but type 'BinaryTreeNode<K, V, NODE>' is not a class derived from 'BSTNode<K, V, NODE>'.

418     map<MK, MV, MR>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: BSTOptions<MK, MV, MR>, thisArg?: any): BST<MK, MV, MR, BSTNode<MK, MV, BSTNodeNested<MK, MV>>>;
        ~~~

node_modules/data-structure-typed/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts:157:5 - error TS2416: Property 'clone' in type 'TreeMultiMap<K, V, R, NODE>' is not assignable to the same property in base type 'RedBlackTree<K, V, R, NODE>'.
  Type '() => TreeMultiMap<K, V, R, NODE>' is not assignable to type '() => this'.
    Type 'TreeMultiMap<K, V, R, NODE>' is not assignable to type 'this'.
      'TreeMultiMap<K, V, R, NODE>' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'TreeMultiMap<K, V, R, NODE>'.

157     clone(): TreeMultiMap<K, V, R, NODE>;
        ~~~~~

Found 4 errors in 3 files.

You can reproduce it by following these steps.

  1. mkdir test && cd test
  2. npm i data-structure-typed typescript @types/node
  3. echo "import 'data-structure-typed';" > test.ts
  4. npx tsc --init
  5. npx tsc test.ts

Note that you wouldn't see these error when you downgrade data-structure-typed to 1.53.8.

$ node --version
v20.17.0
$ npx tsc --version
Version 5.7.2
zrwusa commented 1 week ago

We have solved this problem, please try the new version 1.54.0

snakamura commented 1 week ago

Yes, 1.54.0 fixed the issue. Thank you for your quick update!