janjakubnanista / downsample

Collection of several downsampling methods for time series visualisation purposes.
MIT License
89 stars 9 forks source link

LTTB output not correctly typed (Property 'map' does not exist on type 'Indexable<DataPoint>') #35

Open Akkuma opened 3 years ago

Akkuma commented 3 years ago
import { LTTB } from 'downsample/methods/LTTB'

const t = LTTB([[1,2]], 1)

// Is an array
console.log(Array.isArray(t))

// Is not typed as an array
t.map(console.log)
treystout commented 2 years ago

@Akkuma did you figure out a way to map the result of LTTB? I'm still evaluating the lib and this is the first issue I ran into.

SaltedBlowfish commented 2 years ago

For what it's worth, I ran into this, too. Indexable type looks to return an array-like object, just without the correct methods on the type, so you can safely fix it by type-casting the response as an XYDataPoint array. E.g., XYDataPoint[]

Here's what I mean. Do this:

import { ASAP, XYDataPoint } from "downsample";
...

const downsampledData = ASAP([[0, 1], [1, 2], ...], 1000) as XYDataPoint[];

// now you can treat as an array
downsampledData.map(...)

The original (incorrect) type for Indexable is definitely missing properties of an array. Looks more like an object definition.

type Indexable<T> = {
  length: number;
  [index: number]: T;
};