Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11. Concat #16

Open
astak16 opened this issue May 4, 2022 · 0 comments
Open

11. Concat #16

astak16 opened this issue May 4, 2022 · 0 comments
Labels

Comments

@astak16
Copy link
Owner

astak16 commented May 4, 2022

题目

题目链接:Concat

实现 Concat ,它接收两个参数,两个参数的类型都是数组,将两个数组进行连接,并返回它。

import type { Equal, Expect } from "@type-challenges/utils";

type cases = [
  Expect<Equal<Concat<[], []>, []>>,
  Expect<Equal<Concat<[], [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"]
    >
  >
];

答案

方法一

type Concat<T extends readonly unknown[], F extends readonly unknown[]> = [
  ...T,
  ...U
];
@astak16 astak16 added the easy label May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant