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

TypeScript Array differences

I’m Kinda new to TypeScript and was wondering what is the difference between,
let array: SomeClass[]; and
let array: [SomeClass];?
What does the different positions of the brackets mean?

>Solution :

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

The answer is to do with the amount of instances in each array

someClass[] will mean an array with an infinate length of that class

[someClass] will mean a tuple with a length of one of that class

Ie
someClass[] can be: [someClass], [someClass, someClass] or [someClass, someClass, someClass, someClass] with any amount of values

Whereas [someClass] can only be: [someClass] and no other amount of values in the array

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