Skip to content

获取元祖长度

创建一个通用的Length,接受一个readonly的数组,返回这个数组的长度。

例如:

ts
type tesla = ['tesla', 'model 3', 'model X', 'model Y']
type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT']

type teslaLength = Length<tesla> // expected 4
type spaceXLength = Length<spaceX> // expected 5

  • 请在下面作答:
查看解答
ts
type Length<T extends readonly any[]> = T['length']

Released under the MIT License.