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

Extending nested arrays suddenly stopped working #54983

Closed
RareSecond opened this issue Jul 12, 2023 · 3 comments
Closed

Extending nested arrays suddenly stopped working #54983

RareSecond opened this issue Jul 12, 2023 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@RareSecond
Copy link

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

@geoffreytools
Copy link

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.

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jul 20, 2023
@RyanCavanaugh
Copy link
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)[];
        }[]
    ;
}

@typescript-bot
Copy link
Collaborator

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

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants