1 Star 1 Fork 0

wangzichu/ts-challenges

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
7544.ConstructTuple.ts 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
王子初 提交于 2023-04-28 17:23 . 提交更新
/*
7544 - Construct Tuple
-------
by Lo (@LoTwT) #中等 #tuple
### 题目
构造一个给定长度的元组。
例如
```ts
type result = ConstructTuple<2> // 期望得到 [unknown, unkonwn]
```
> 在 Github 上查看:https://tsch.js.org/7544/zh-CN
*/
/* _____________ 你的代码 _____________ */
type ConstructTuple<L extends number,arr extends unknown[] = []> = arr['length'] extends L ? arr : ConstructTuple<L,[...arr,unknown]>
/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<ConstructTuple<0>, []>>,
Expect<Equal<ConstructTuple<2>, [unknown, unknown]>>,
Expect<Equal<ConstructTuple<999>['length'], 999>>,
// @ts-expect-error
Expect<Equal<ConstructTuple<1000>['length'], 1000>>,
]
/* _____________ 下一步 _____________ */
/*
> 分享你的解答:https://tsch.js.org/7544/answer/zh-CN
> 查看解答:https://tsch.js.org/7544/solutions
> 更多题目:https://tsch.js.org/zh-CN
*/
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wang-zichu/ts-challenges.git
git@gitee.com:wang-zichu/ts-challenges.git
wang-zichu
ts-challenges
ts-challenges
master

搜索帮助