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

Cannot use layers with typescript #1322

Closed
mdesousa opened this issue Dec 2, 2020 · 2 comments
Closed

Cannot use layers with typescript #1322

mdesousa opened this issue Dec 2, 2020 · 2 comments
Labels
📊 bar @nivo/bar package

Comments

@mdesousa
Copy link

mdesousa commented Dec 2, 2020

It appears that with typescript it is not possible to declare layers for the ResponsiveBar component. This is with version 0.65.1 of @nivo/bar.
If your try to use the default string array["grid", "axes", "bars", "markers", "legends", "annotations"] you get type errors (e.g. Type '"grid"' is not assignable to type 'Layer').
The typescript definition seems to be using an enum type (BarLayerType):

export enum BarLayerType {
    Grid = 'grid',
    Axes = 'axes',
    Bars = 'bars',
    Markers = 'markers',
    Legends = 'legends',
}
export type BarCustomLayer = (props: any) => React.ReactNode
export type Layer = BarLayerType | BarCustomLayer

I tried importing BarLayerType and using enums, like this:

import { BarItemProps, BarLayerType, ResponsiveBar } from "@nivo/bar";
...
  <ResponsiveBar
    layers={[
      BarLayerType.Grid,
      BarLayerType.Axes,
      BarLayerType.Bars,
      BarLayerType.Markers,
      BarLayerType.Legends,
    ]}

This looks ok in the vscode linter. However, when you start the react project you get an error: Attempted import error: 'BarLayerType' is not exported from '@nivo/bar'.
This is confusing since there is an "export" in the declaration file... but it's what happens.
I would like to recommend to change the BarLayerType to be a string union instead of an enum, like this:

type BarLayerType = "grid" | "axes" | "bars" | "markers" | "legends" | "annotations"
@wyze
Copy link
Contributor

wyze commented Dec 2, 2020

We are using string unions for the charts that have been converted to typescript, Pie, Sunburst. So when we get around to converting it, we will make this change.

Feel free to make a PR sooner if you would like to make that change!

@plouc
Copy link
Owner

plouc commented Dec 3, 2020

Fixed by #1323

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📊 bar @nivo/bar package
Projects
None yet
Development

No branches or pull requests

3 participants