Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Akkuma opened this issue Aug 15, 2021 · 2 comments

Comments

@Akkuma
Copy link

Akkuma commented Aug 15, 2021

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
Copy link

@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
Copy link

SaltedBlowfish commented Jul 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants