1 Star 1 Fork 0

wangzichu/ts-challenges

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
3057.push.ts 679 Bytes
Copy Edit Raw Blame History
WangZiChu199910252255 authored 2022-11-04 11:22 . 提交
/*
3057 - Push
-------
by jiangshan (@jiangshanmeta) #简单 #array
### 题目
在类型系统里实现通用的 ```Array.push``` 。
例如:
```typescript
type Result = Push<[1, 2], '3'> // [1, 2, '3']
```
> 在 Github 上查看:https://tsch.js.org/3057/zh-CN
*/
/* _____________ 你的代码 _____________ */
type Push<T extends Array<any>, U> = [...T,U]
/* _____________ 测试用例 _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<Push<[], 1>, [1]>>,
Expect<Equal<Push<[1, 2], '3'>, [1, 2, '3']>>,
Expect<Equal<Push<['1', 2, '3'], boolean>, ['1', 2, '3', boolean]>>,
]
马建仓 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

Search