Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

After all, which the difference between string[] | number[] and (string | number)[]?

I was looking for some codes on github and I found some interfaces with

interface A {
  type: string[] | number[]
}

and others like

interface A {
  type: (string | number)[]
}

But, whitch the difference?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The first is "an array of strings or an array of numbers". In which the array can contain strings or numbers, but not a mix of both.

The second is "an array of strings or numbers". In which the array can contain strings, numbers, or a mix of both.

Consider them structurally as:

(an array of strings) or (an array of numbers)

and

an array of (strings or numbers)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading