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

Use readonly types for arrays where appropriate #2248

Open
evantrimboli opened this issue Feb 22, 2023 · 1 comment
Open

Use readonly types for arrays where appropriate #2248

evantrimboli opened this issue Feb 22, 2023 · 1 comment

Comments

@evantrimboli
Copy link

evantrimboli commented Feb 22, 2023

Is your feature request related to a problem? Please describe.
It's not possible to pass readonly arrays for chart data, legends and other props that aren't mutated.

Describe the solution you'd like
Types should use readonly where appropriate:

export interface DataProps<RawDatum> {
  data: readonly RawDatum[];
}

Describe alternatives you've considered
N/A

Additional context
This has 2 benefits:

  • It communicates intent better, so the caller can be sure the array itself isn't mutated
  • For those using readonly arrays in the code, it makes it simpler because there's no need to shallow clone or cast.
@plouc
Copy link
Owner

plouc commented Feb 26, 2023

That's indeed a really good idea, I had issues achieving this due to D3 typings, because D3 often mutates data, so the lib would have to handle what currently has to be done in user space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants