Skip to content

Commit

Permalink
[typo]: more appropriate wording for zh (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
likui628 authored Feb 1, 2022
1 parent 7d73fe3 commit 20550d1
Show file tree
Hide file tree
Showing 18 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions _data/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ zh:
archive-tag: "归档标签 '%1'"
comments: "评论"
challenge: "挑战"
solution: "解法"
solution: "解答"
warm: "热身"
easy: "简单"
medium: "一般"
hard: ""
extreme: "很难"
medium: "中等"
hard: "困难"
extreme: "地狱"
4 changes: 2 additions & 2 deletions zh/easy-awaited.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tags: promise
我们如何获得包装类型的内部类型?
例如,如果我们有`Promise<ExampleType>`如何得到`ExampleType` ?

## 解法
## 解答

这是一个非常有趣的挑战,它要求我们了解 TypeScript 的一个被低估的特性,恕我直言。

Expand Down Expand Up @@ -45,7 +45,7 @@ type Awaited<T> = T extends Promise<string> ? string : T;
你可以对编译器说"嘿,一旦你知道了类型是什么,请把它赋给我的类型参数"。
你可以在这里阅读更多关于[条件类型中的类型推断](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#type-inference-in-conditional-types)

了解了类型推断之后,我们可以更新我们的解法
了解了类型推断之后,我们可以更新我们的解答
我们没有在条件类型中检查`Promise<string>`,而是将`string`替换为`infer R`,因为我们不知道那里必须有什么。
我们只知道它是`Promise<T>`,其内部包含某种类型。

Expand Down
2 changes: 1 addition & 1 deletion zh/easy-concat.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tags: array
type Result = Concat<[1], [2]>; // expected to be [1, 2]
```

## 解法
## 解答

在 TypeScript 中处理数组时,变参元组类型通常会在某些情况下发挥作用。他们允许我们进行泛型展开。稍后我会试着说明。

Expand Down
4 changes: 2 additions & 2 deletions zh/easy-exclude.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type T0 = Exclude<"a" | "b" | "c", "a">; // expected "b" | "c"
type T1 = Exclude<"a" | "b" | "c", "a" | "b">; // expected "c"
```

## 解法
## 解答

这里重要的细节是 TypeScript 中的条件类型是[可分配的](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types)

所以当你在写`T extends U``T`是联合类型时,实际上发生的是 TypeScript 遍历联合类型`T`并将条件应用到每个元素上。

因此,这个解法是非常直接的。我们检查`T`如果可以分配给`U`则跳过:
因此,这个解答是非常直接的。我们检查`T`如果可以分配给`U`则跳过:

```ts
type MyExclude<T, U> = T extends U ? never : T;
Expand Down
2 changes: 1 addition & 1 deletion zh/easy-first.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type head1 = First<arr1>; // expected to be 'a'
type head2 = First<arr2>; // expected to be 3
```

## 解法
## 解答

首先我们想到的就是使用查询类型,然后写出`T[0]`

Expand Down
2 changes: 1 addition & 1 deletion zh/easy-if.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type A = If<true, "a", "b">; // expected to be 'a'
type B = If<false, "a", "b">; // expected to be 'b'
```

## 解法
## 解答

如果你不确定什么时候在 TypeScript 中使用[条件类型](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html),那就是你需要对类型使用“if”语句的时候。这正是我们这里要做的。

Expand Down
2 changes: 1 addition & 1 deletion zh/easy-includes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tags: array
type isPillarMen = Includes<["Kars", "Esidisi", "Wamuu", "Santana"], "Dio">;
```

## 解法
## 解答

我们首先编写接受两个参数的类型:`T`(元组)和`U`(我们正在寻找的)。

Expand Down
2 changes: 1 addition & 1 deletion zh/easy-pick.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const todo: TodoPreview = {
};
```

## 解法
## 解答

为了解出这个挑战,我们需要使用查找类型和映射类型。

Expand Down
2 changes: 1 addition & 1 deletion zh/easy-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tags: array
type Result = Push<[1, 2], "3">; // [1, 2, '3']
```

## 解法
## 解答

这个实际上很简单。
要实现一个将元素插入数组的类型,我们需要做 2 件事。
Expand Down
2 changes: 1 addition & 1 deletion zh/easy-readonly.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ todo.title = "Hello"; // Error: cannot reassign a readonly property
todo.description = "barFoo"; // Error: cannot reassign a readonly property
```

## 解法
## 解答

我们需要使对象中的所有属性都是只读的。
因此,我们需要迭代所有的属性,并为它们添加一个修饰符。
Expand Down
2 changes: 1 addition & 1 deletion zh/easy-tuple-length.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type teslaLength = Length<tesla>; // expected 4
type spaceXLength = Length<spaceX>; // expected 5
```

## 解法
## 解答

我们知道在 JavaScript 中可以使用属性`length`来访问数组的长度。
我们也可以在类型上做同样的事情:
Expand Down
2 changes: 1 addition & 1 deletion zh/easy-tuple-to-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const tuple = ["tesla", "model 3", "model X", "model Y"] as const;
const result: TupleToObject<typeof tuple>;
```

## 解法
## 解答

我们需要从数组中获取所有的值,并将其作为新对象中的键和值。

Expand Down
2 changes: 1 addition & 1 deletion zh/easy-unshift.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tags: array
type Result = Unshift<[1, 2], 0>; // [0, 1, 2]
```

## 解法
## 解答

这个挑战和[Push challenge](./easy-push.md)有很多相似之处。
在这里,我们使用可变元组类型(Variadic Tuple Types)来获取数组中的所有元素。
Expand Down
2 changes: 1 addition & 1 deletion zh/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ comments: false

现在,我建议你从"热身"开始,逐渐地向"很难"级别前进。
首先,打开"挑战"链接并尝试自己解出。
如果你无法解出,请返回此处并打开"解法"。
如果你无法解出,请返回此处并打开"解答"。

事不宜迟,慢慢来,享受挑战!

Expand Down
2 changes: 1 addition & 1 deletion zh/medium-absolute.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Test = -100;
type Result = Absolute<Test>; // expected to be "100"
```

## 解法
## 解答

获得一个数字的绝对值最简单的方法是将其转换为字符串并去掉“-”号。我不是在开玩笑,只是去掉“-”号。

Expand Down
2 changes: 1 addition & 1 deletion zh/medium-append-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Fn = (a: number, b: string) => number;
type Result = AppendArgument<Fn, boolean>;
```

## 解法
## 解答

这是一个有趣的挑战, 其中包含了类型推断,可变元组类型,条件类型以及其他很多有趣的东西。

Expand Down
2 changes: 1 addition & 1 deletion zh/medium-flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tags: array
type flatten = Flatten<[1, 2, [3, 4], [[[5]]]> // [1, 2, 3, 4, 5]
```
## 解法
## 解答
该挑战的基本用例是一个空数组的情况。当我们输入一个空数组时,我们返回一个空数组, 反正它已经被展平了。否则,返回`T` 本身:
Expand Down
2 changes: 1 addition & 1 deletion zh/warm-hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type HelloWorld = any;
type test = Expect<Equal<HelloWorld, string>>;
```

## 解法
## 解答

这是一个热身挑战,让你熟悉他们的练习场,如何接受挑战等等。
我们在这里需要做的只是将类型设置为' string '替代原来的' any ':
Expand Down

0 comments on commit 20550d1

Please sign in to comment.