Skip to content

Extending nested arrays suddenly stopped workingΒ #54983

Closed as not planned
Closed as not planned

Description

@RareSecond

Bug Report

πŸ”Ž Search Terms

nested array

πŸ•— Version & Regression Information

  • This changed between versions 4.3.5 and 4.4.2

⏯ Playground Link

Failing playground
Correct playground

πŸ’» Code

interface ChartState {
    labels: string[];
    datasets: [
        {
            label: string;
            backgroundColor: string[] | string;
            hoverBackgroundColor: string[] | string;
            data:  (string|number)[];
        }
    ];
}

type _dataSetType = ChartState['datasets'][0];

type _barChartDataSetType = _dataSetType & {
   barThickness: number;
}

export type BarCharState = ChartState & {
  datasets: Array<_barChartDataSetType>
}

const test: BarCharState = {
   labels: ['foo', 'bar'],
   datasets: [
      {
         label: 'foo',
         backgroundColor: '#fefefe',
         hoverBackgroundColor: '#ffffff',
         data: ['a', 'b'],
         barThickness: 3,
      },
   ]
}

πŸ™ Actual behavior

It does not correctly merge the two types

πŸ™‚ Expected behavior

The resulting type displays incorrect behavior

Activity

  1. geoffreytools commented on Jul 14, 2023

    @geoffreytools

    It could be a bug related to this issue but ChartState/datasets should be defined as an array. This intersection between a tuple and an array does not make much sense and is best avoided.

  2. RyanCavanaugh commented on Jul 20, 2023

    @RyanCavanaugh
    Member

    It really seems like you wrote [T] thinking it meant T[]. This works as expected:

    interface ChartState {
        labels: string[];
        datasets: 
            {
                label: string;
                backgroundColor: string[] | string;
                hoverBackgroundColor: string[] | string;
                data:  (string|number)[];
            }[]
        ;
    }
  3. typescript-bot commented on Jul 23, 2023

    @typescript-bot
    Contributor

    This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  4. locked as resolved and limited conversation to collaborators on Oct 22, 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

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions