type Concat<T extends any[]|readonly any[], U extends any[]|readonly any[]> = [...T,...U];
Solution by lephuthuc2001 #34712
// your answers
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [ ...T, ...U ];
Solution by zeyuanHong0 #34707
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by Git-I985 #34704
type Concat<T, U> = T extends readonly any[] ? U extends readonly any[] ? [...T, ...U] : never : never
Solution by nathan2slime #34661
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by Hailey0930 #34637
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T,...U]
Solution by DevShinnThant #34547
// your answers
Solution by DevShinnThant #34546
// 여기 풀이를 입력하세요
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U];
Solution by LeeKangHyun #34462
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U]
// Note that: readonly is only permitted on array and tuple literal types ⇒ it means that it doesn’t work with generic like Array<unknown>
Solution by binhdv155127 #34443
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U];
Solution by ktim816 #34425
// your answers
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by gobielJonathan #34398
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U]
Solution by rookie-luochao #34360
type Concat<P, Q> = [
...P extends any[] ? P : [P],
...Q extends any[] ? Q : [Q],
]
考虑到P,Q可能不一定是数组类型(元组是特殊的数组类型),因此将any[]的写法从泛型中提取出来,分别对应到P和Q中。
Solution by wxh-cyber #34346
We just use the spread Operator.
But we should check T and U extends readonly unknown[]
because of [...] as const
inputs.
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U]
Solution by dev-jaemin #34329
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U];
注意,如果没有加入readonly,在处理元组类型时会报错。
Solution by wxh-cyber #34324
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by bkdragon0228 #34321
type Concat<
A extends unknown[],
B extends unknown[]
> = [...A, ...B]
Solution by souzaramon #34268
// 你的答案
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T,...U]
Solution by W-fitTiger #34248
// 你的答案
type Concat<T extends readonly any[], U extends readonly any[]> = [...T,...U]
Solution by Hadias94 #34216
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by quitone #34194
JavaScript의 Array.concat
함수를 타입 시스템에서 구현하세요. 타입은 두 인수를 받고, 인수를 왼쪽부터 concat한 새로운 배열을 반환해야 합니다.
예시:
type Result = Concat<[1], [2]>; // expected to be [1, 2]
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U];
array의 spread method를 사용하여 어렵지 않게 해결할 수 있었습니다!
/* _____________ 여기에 코드 입력 _____________ */
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U];
/* _____________ 테스트 케이스 _____________ */
import type { Equal, Expect } from "@type-challenges/utils";
const tuple = [1] as const;
type cases = [
Expect<Equal<Concat<[], []>, []>>,
Expect<Equal<Concat<[], [1]>, [1]>>,
Expect<Equal<Concat<typeof tuple, typeof tuple>, [1, 1]>>,
Expect<Equal<Concat<[1, 2], [3, 4]>, [1, 2, 3, 4]>>,
Expect<
Equal<
Concat<["1", 2, "3"], [false, boolean, "4"]>,
["1", 2, "3", false, boolean, "4"]
>
>
];
Solution by adultlee #34124
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U];
Solution by ProvorovOleksii #34079
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]```
Solution by ouzexi #33970
type Concat<T extends readonly any[], U extends readonly any[]> = [...T,...U]
Solution by vuongle2609 #33934
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by hanseulhee #33874
type Concat<T extends readonly any[], U extends readonly any[]> = [...T, ...U]
Solution by notsecret32 #33862
type Concat<T extends Readonly<Array<unknown>>, U extends Readonly<Array<unknown>>> = [...T,...U]
Solution by d0422 #33814
type Concat<T extends Tuple , U extends Tuple> = [...T, ...U]
Solution by okasyun #33775
type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U]
Solution by veralex #33755
type Concat<T, U> = T extends readonly any[]
? U extends readonly any[]
? [...T, ...U]
: never
: never
Solution by laplace1009 #33706