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

Type with string indexes of array

In some third-party code I found a strange type definition which I didn’t see before.

type SomeType = [from: number, to: number];

No idea how this is called in docs so I could not find anything about it. Can someone explain me please what does it mean?

PS. const q: SomeType = [1, 2]; compiles just fine so I guess it’s still a simple array of two numbers.

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 :

It is Labeled tuple elements

Treat labels from and to just as a comments. They don’t affect type itself in any way. It is just for readability.

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