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.

Activity

added
bugsomething broken
P2considered for next cycle
on Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @gvwilson@amrtgaber

        Issue actions

          Incorrect type error when assigning string to automargin property in LayoutAxis · Issue #7331 · plotly/plotly.js