From 8ca8cc481b48fb4ad4d1498a835a74c4b3c604ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=A7=E6=B5=AA?= Date: Wed, 29 Jul 2020 18:54:26 +0800 Subject: [PATCH] feat(question): add tuple length (#17) * feat(question): add tuple length * Update questions/18-easy-tuple-length/info.yml Accept suggestion Co-authored-by: Anthony Fu * refactor(question): add tags tuple Co-authored-by: Anthony Fu --- README.md | 2 +- README.zh-CN.md | 2 +- questions/18-easy-tuple-length/README.md | 15 +++++++++++++++ questions/18-easy-tuple-length/info.yml | 8 ++++++++ questions/18-easy-tuple-length/info.zh-CN.yml | 1 + questions/18-easy-tuple-length/template.ts | 1 + questions/18-easy-tuple-length/test-cases.ts | 9 +++++++++ 7 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 questions/18-easy-tuple-length/README.md create mode 100644 questions/18-easy-tuple-length/info.yml create mode 100644 questions/18-easy-tuple-length/info.zh-CN.yml create mode 100644 questions/18-easy-tuple-length/template.ts create mode 100644 questions/18-easy-tuple-length/test-cases.ts diff --git a/README.md b/README.md index 2406eef6..66836533 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This project is aim to make you better understand how the type system works, wri > Click the following badges to see detail of the challenges! -
13・Hello World


4・Pick<T, K> 7・Readonly<T> 11・Tuple to Object 14・First of Array


2・Get Return Type 3・Omit<T, K> 8・Readonly 2 9・Deep Readonly 10・Tuple to Union 12・Chainable Options 15・Last of Array 16・Pop


6・Simple Vue 17・Currying 1


5・Get Readonly Keys
By Tags
#4.014・First of Array 15・Last of Array 16・Pop 17・Currying 1
#application12・Chainable Options 6・Simple Vue
#array14・First of Array 15・Last of Array 16・Pop 17・Currying 1
#built-in4・Pick<T, K> 7・Readonly<T> 2・Get Return Type 3・Omit<T, K>
#deep9・Deep Readonly
#infer2・Get Return Type 10・Tuple to Union
#object-keys7・Readonly<T> 8・Readonly 2 9・Deep Readonly 5・Get Readonly Keys
#readonly7・Readonly<T> 8・Readonly 2 9・Deep Readonly
#this6・Simple Vue
#tuple10・Tuple to Union
#union4・Pick<T, K> 3・Omit<T, K> 10・Tuple to Union
#utils5・Get Readonly Keys
+
13・Hello World


4・Pick<T, K> 7・Readonly<T> 11・Tuple to Object 14・First of Array 18・Tuple length


2・Get Return Type 3・Omit<T, K> 8・Readonly 2 9・Deep Readonly 10・Tuple to Union 12・Chainable Options 15・Last of Array 16・Pop


6・Simple Vue 17・Currying 1


5・Get Readonly Keys
By Tags
#4.014・First of Array 15・Last of Array 16・Pop 17・Currying 1
#application12・Chainable Options 6・Simple Vue
#array14・First of Array 15・Last of Array 16・Pop 17・Currying 1
#built-in4・Pick<T, K> 7・Readonly<T> 2・Get Return Type 3・Omit<T, K>
#deep9・Deep Readonly
#infer2・Get Return Type 10・Tuple to Union
#object-keys7・Readonly<T> 8・Readonly 2 9・Deep Readonly 5・Get Readonly Keys
#readonly7・Readonly<T> 8・Readonly 2 9・Deep Readonly
#this6・Simple Vue
#tuple18・Tuple length 10・Tuple to Union
#union4・Pick<T, K> 3・Omit<T, K> 10・Tuple to Union
#utils5・Get Readonly Keys
## Recommended Readings diff --git a/README.zh-CN.md b/README.zh-CN.md index 785181ec..cb954b0a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -30,7 +30,7 @@ TypeScript 类型体操姿势合集 > 点击下方徽章查看题目内容 -
13・Hello World


4・实现 Pick<T, K> 7・实现 Readonly<T> 11・元组转换为对象 14・第一个元素


2・获取函数返回类型 3・实现 Omit<T, K> 8・Readonly 2 9・深度 Readonly 10・元组转合集 12・可串联构造器 15・最后一个元素 16・出堆


6・简单的 Vue 类型 17・科里化 1


5・获取只读字段
By Tags
#4.014・第一个元素 15・最后一个元素 16・出堆 17・科里化 1
#application12・可串联构造器 6・简单的 Vue 类型
#array14・第一个元素 15・最后一个元素 16・出堆 17・科里化 1
#built-in4・实现 Pick<T, K> 7・实现 Readonly<T> 2・获取函数返回类型 3・实现 Omit<T, K>
#deep9・深度 Readonly
#infer2・获取函数返回类型 10・元组转合集
#object-keys7・实现 Readonly<T> 8・Readonly 2 9・深度 Readonly 5・获取只读字段
#readonly7・实现 Readonly<T> 8・Readonly 2 9・深度 Readonly
#this6・简单的 Vue 类型
#tuple10・元组转合集
#union4・实现 Pick<T, K> 3・实现 Omit<T, K> 10・元组转合集
#utils5・获取只读字段
+
13・Hello World


4・实现 Pick<T, K> 7・实现 Readonly<T> 11・元组转换为对象 14・第一个元素 18・获取元组长度


2・获取函数返回类型 3・实现 Omit<T, K> 8・Readonly 2 9・深度 Readonly 10・元组转合集 12・可串联构造器 15・最后一个元素 16・出堆


6・简单的 Vue 类型 17・科里化 1


5・获取只读字段
By Tags
#4.014・第一个元素 15・最后一个元素 16・出堆 17・科里化 1
#application12・可串联构造器 6・简单的 Vue 类型
#array14・第一个元素 15・最后一个元素 16・出堆 17・科里化 1
#built-in4・实现 Pick<T, K> 7・实现 Readonly<T> 2・获取函数返回类型 3・实现 Omit<T, K>
#deep9・深度 Readonly
#infer2・获取函数返回类型 10・元组转合集
#object-keys7・实现 Readonly<T> 8・Readonly 2 9・深度 Readonly 5・获取只读字段
#readonly7・实现 Readonly<T> 8・Readonly 2 9・深度 Readonly
#this6・简单的 Vue 类型
#tuple18・获取元组长度 10・元组转合集
#union4・实现 Pick<T, K> 3・实现 Omit<T, K> 10・元组转合集
#utils5・获取只读字段
## 推荐读物 diff --git a/questions/18-easy-tuple-length/README.md b/questions/18-easy-tuple-length/README.md new file mode 100644 index 00000000..95054d24 --- /dev/null +++ b/questions/18-easy-tuple-length/README.md @@ -0,0 +1,15 @@ +

Tuple length easy #tuple

by sinoon @sinoon

Take the Challenge

+ +For given a tuple, you need create a generic `Length`, pick the length of the tuple + +For example + +```ts +type tesla = ['tesla', 'model 3', 'model X', 'model Y'] +type spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] + +type teslaLength = Length // expected 4 +type spaceXLength = Length // expected 5 +``` + +
Back Check out Solutions Share your Solutions diff --git a/questions/18-easy-tuple-length/info.yml b/questions/18-easy-tuple-length/info.yml new file mode 100644 index 00000000..b3af3353 --- /dev/null +++ b/questions/18-easy-tuple-length/info.yml @@ -0,0 +1,8 @@ +title: Length of Tuple + +author: + name: sinoon + email: sinoon1218@gamil.com + github: sinoon + +tags: tuple diff --git a/questions/18-easy-tuple-length/info.zh-CN.yml b/questions/18-easy-tuple-length/info.zh-CN.yml new file mode 100644 index 00000000..9164202d --- /dev/null +++ b/questions/18-easy-tuple-length/info.zh-CN.yml @@ -0,0 +1 @@ +title: 获取元组长度 diff --git a/questions/18-easy-tuple-length/template.ts b/questions/18-easy-tuple-length/template.ts new file mode 100644 index 00000000..90316925 --- /dev/null +++ b/questions/18-easy-tuple-length/template.ts @@ -0,0 +1 @@ +type Length = any diff --git a/questions/18-easy-tuple-length/test-cases.ts b/questions/18-easy-tuple-length/test-cases.ts new file mode 100644 index 00000000..c84684e3 --- /dev/null +++ b/questions/18-easy-tuple-length/test-cases.ts @@ -0,0 +1,9 @@ +import { Equal, Expect } from '@type-challenges/utils' + +const tesla = ['tesla', 'model 3', 'model X', 'model Y'] +const spaceX = ['FALCON 9', 'FALCON HEAVY', 'DRAGON', 'STARSHIP', 'HUMAN SPACEFLIGHT'] + +type cases = [ + Expect, 4>>, + Expect, 5>>, +]