2

I have the following type(s):

const type Person = [string, number, number]

const type Person = [
  string, // name
  number, // age
  number // height
]

Is it possible to add comments to what the elements are? Or any conventions? Like with function: Where is the syntax for TypeScript comments documented?

Lars Flieger
  • 2,421
  • 1
  • 12
  • 34
  • Why aren't you using typed objects (with properties)? Or classes? https://www.typescriptlang.org/docs/handbook/2/classes.html – birgersp May 25 '22 at 12:07
  • @birgersp Because sometimes an array is the correct tool, the specific type description given as an example isn't all that important for the question imo. A good example would be coordinate systems where you often work with tuples of different kinds and it would be very handy to know which one is longitude and which is latitude etc, since they differ between different systems. – Etheryte May 25 '22 at 12:08
  • @birgersp Thanks for the idea. I have to migrate data to a new schema and the new type is an object. But the old data is not changeable. :/ – Lars Flieger May 25 '22 at 12:11

1 Answers1

3

I think the closest solution is Labeled tuple elements

const type Person = [name: string, age: number, height: number]