首页 > 其他分享 >[TypeScript] Labelled tuple type

[TypeScript] Labelled tuple type

时间:2022-08-22 15:12:23浏览次数:52  
标签:TypeScript string tuple address number Labelled Address type

Let's see the unlabelled tuple type:

type Address = [
  number,
  string,
  string,
  number,
]

function printAddress(...address: Address) {
  console.log(address)
}

As you can see, the auto completion is not good.

 

Then see the labelled tuple types:

type Address_Label = [
  streetNumber: number,
  streeName: string,
  city: string,
  postCode: number,
]

function printAddress2(...address: Address_Label) {
  console.log(address)
}

Once you label one tuple type, you have to label all the tuple.

标签:TypeScript,string,tuple,address,number,Labelled,Address,type
From: https://www.cnblogs.com/Answer1215/p/16612851.html

相关文章