downsample icon indicating copy to clipboard operation
downsample copied to clipboard

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

Open Akkuma opened this issue 3 years ago • 2 comments

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)

Akkuma avatar Aug 15 '21 15:08 Akkuma

@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.

treystout avatar Mar 21 '22 23:03 treystout

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;
};

SaltedBlowfish avatar Jul 30 '22 20:07 SaltedBlowfish