Skip to content

Incorrect type error when assigning string to automargin property in LayoutAxis #7331

Open
@amrtgaber

Description

@amrtgaber

I'm getting what I believe to be an incorrect type error. I'm using typescript and I needed to set the automargin for the xaxis to "bottom" to avoid an infinite automargin loop. When I did that I got a type error that string is not assignable to type "boolean | undefined".

Screenshot:
Image

However the automargin behaves as expected and the infinite automargin loop is gone so it's clear that the value can indeed be a string. I fixed it by augmenting the LayoutAxis and Layout type like so.

interface AugmentedLayoutAxis extends Omit<LayoutAxis, "automargin"> {
  automargin: string | boolean;
}

interface AugmentedLayout extends Omit<Layout, "xaxis"> {
  xaxis: Partial<AugmentedLayoutAxis>;
}

Screenshot:
Image

But then I also had to cast it in the component layout property

Screenshot:
Image

I believe the fix is to update the LayoutAxis type in @types/plotly.js here: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/plotly.js/index.d.ts#L937

Hope this helps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions