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

bug(cdk): coerceArray doesn't work with readonly arrays #18806

Comments

@klemenoslaj
Copy link
Contributor

klemenoslaj commented Mar 12, 2020

Reproduction

Use StackBlitz to reproduce your issue: https://stackblitz.com/fork/components-issue

Steps to reproduce:

  1. Open: https://stackblitz.com/edit/components-issue-axn4qw?embed=1&file=src/app/example-component.ts&view=editor
  2. TS compile error appears

Expected Behavior

What behavior were you expecting to see?

coerceArray should preserve the readonly array.

Actual Behavior

What behavior did you actually see?
An error:

Argument of type 'readonly number[]' is not assignable to parameter of type 'number | number[]'.
  The type 'readonly number[]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.

Environment

dependencies from stackblitz

  • Angular: 9.0.2
  • CDK/Material: 9.1.0

My thoughts

Type definition is:

export declare function coerceArray<T>(value: T | T[]): T[];

I think it should b:

export declare function coerceArray<T>(value: T | readonly T[]): T[];

This way it would accept both mutable and readonly arrays.

@klemenoslaj klemenoslaj added the needs triage This issue needs to be triaged by the team label Mar 12, 2020
klemenoslaj added a commit to klemenoslaj/components that referenced this issue Mar 12, 2020
Fixes a type definition of coerceArray so that it accepts both mutable and
immutable arrays.

Fixes angular#18806
klemenoslaj added a commit to klemenoslaj/components that referenced this issue Mar 12, 2020
Fixes a type definition of coerceArray so that it accepts both mutable and
immutable arrays.

Fixes angular#18806
klemenoslaj added a commit to klemenoslaj/components that referenced this issue Mar 12, 2020
Fixes a type definition of coerceArray so that it accepts both mutable and
immutable arrays.

Fixes angular#18806
@crisbeto crisbeto added has pr and removed needs triage This issue needs to be triaged by the team labels Mar 14, 2020
mmalerba pushed a commit that referenced this issue Mar 21, 2020
Fixes a type definition of coerceArray so that it accepts both mutable and
immutable arrays.

Fixes #18806
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.