Skip to content

实现Concat

在类型系统里实现JavaScript内置的Array.concat方法,这个类型接受两个参数,返回的新数组类型应该按照输入参数从左到右的顺序合并为一个新的数组。

例如:

ts
type Result = Concat<[1], [2]> // expected to be [1, 2]
  • 在下方作答:
查看解答
ts
type Concat<T extends any[], U extends any[]> = [...T, ...U]

Released under the MIT License.