alexbol99 / flatten-interval-tree

Interval binary search tree
MIT License
41 stars 21 forks source link

Typescript usage of SearchOutput is any? #50

Open cmdcolin opened 6 months ago

cmdcolin commented 6 months ago

hello. thanks for this useful library! I was wondering if there is any hint to make typescript recognize the returned type of search

it is often type any

example

import IntervalTree from '@flatten-js/interval-tree';

let tree = new IntervalTree<string>();

let intervals = [
  [6, 8],
  [1, 4],
  [5, 12],
  [1, 1],
  [5, 7],
] as [number, number][];

// Insert interval as a key and string "val0", "val1" etc. as a value
for (let i = 0; i < intervals.length; i++) {
  tree.insert(intervals[i], 'val' + i);
}

// Get array of keys sorted in ascendant order
let sorted_intervals = tree.keys; //  expected array [[1,1],[1,4],[5,7],[5,12],[6,8]]

// Search items which keys intersect with given interval, and return array of values
let values_in_range = tree.search([2, 3]); // values_in_range is SearchOutput<string>
const x=values_in_range[0] //<-- x is any
let values_in_range = tree.search([2, 3]).forEach((e) => { //<-- e is any
  console.log('e', e);
});